12
12
VC_DATASTORE , VC_DATACENTER , NETWORK , TEMPLATE , VC_CLUSTER
13
13
14
14
from agent import reset_container_host , check_daemon , \
15
- create_vm , delete_vm , check_vc_resource , \
16
- initializesi
15
+ VsphereOperation
17
16
18
17
from ..host_base import HostBase
19
18
20
19
logger = logging .getLogger (__name__ )
21
20
logger .setLevel (LOG_LEVEL )
22
21
logger .addHandler (log_handler )
22
+ operation = VsphereOperation ()
23
23
24
24
25
25
class VsphereHost (HostBase ):
@@ -40,25 +40,25 @@ def create(self, vcip, username, pwd, port, params):
40
40
"""
41
41
# Init connection
42
42
try :
43
- si = initializesi (vcip , username , pwd , port )
43
+ si = operation . initializesi (vcip , username , pwd , port )
44
44
connection = si .RetrieveContent ()
45
45
vc_resources = params .get (VCENTER )
46
46
47
47
except Exception as e :
48
48
error_msg = (
49
- "Cannot complete login due to "
50
- " an incorrect user name or password."
49
+ "Cannot complete login due"
50
+ "to an incorrect user name or password."
51
51
)
52
52
raise Exception (error_msg )
53
53
54
54
# Check cluster
55
- cluster = check_vc_resource (connection ,
56
- [vim .ClusterComputeResource ],
57
- vc_resources [VC_CLUSTER ])
55
+ cluster = operation . check_vc_resource (connection ,
56
+ [vim .ClusterComputeResource ],
57
+ vc_resources [VC_CLUSTER ])
58
58
if cluster is None :
59
59
error_msg = (
60
60
"The Cluster: {} does not exist"
61
- " or exception is raised."
61
+ "or exception is raised."
62
62
).format (vc_resources [VC_CLUSTER ])
63
63
64
64
logger .error (error_msg )
@@ -68,13 +68,13 @@ def create(self, vcip, username, pwd, port, params):
68
68
vc_resources [VC_CLUSTER ] = cluster
69
69
70
70
# Check datacenter
71
- datacenter = check_vc_resource (connection ,
72
- [vim .Datacenter ],
73
- vc_resources [VC_DATACENTER ])
71
+ datacenter = operation . check_vc_resource (connection ,
72
+ [vim .Datacenter ],
73
+ vc_resources [VC_DATACENTER ])
74
74
if datacenter is None :
75
75
error_msg = (
76
- "The DataCenter: {} does not exist"
77
- " or exception is raised."
76
+ "The DataCenter: {} does not exist, "
77
+ "or exception is raised."
78
78
).format (vc_resources [VC_DATACENTER ])
79
79
80
80
logger .error (error_msg )
@@ -84,13 +84,13 @@ def create(self, vcip, username, pwd, port, params):
84
84
vc_resources [VC_DATACENTER ] = datacenter
85
85
86
86
# Check datastore
87
- datastore = check_vc_resource (connection ,
88
- [vim .Datastore ],
89
- vc_resources [VC_DATASTORE ])
87
+ datastore = operation . check_vc_resource (connection ,
88
+ [vim .Datastore ],
89
+ vc_resources [VC_DATASTORE ])
90
90
if datastore is None :
91
91
error_msg = (
92
- "The Datastore: {} does not exist"
93
- " or exception is raised."
92
+ "The Datastore: {} does not exist, "
93
+ "or exception is raised."
94
94
).format (vc_resources [VC_DATASTORE ])
95
95
96
96
logger .error (error_msg )
@@ -100,13 +100,13 @@ def create(self, vcip, username, pwd, port, params):
100
100
vc_resources [VC_DATASTORE ] = datastore
101
101
102
102
# Check template
103
- template = check_vc_resource (connection ,
104
- [vim .VirtualMachine ],
105
- vc_resources [TEMPLATE ])
103
+ template = operation . check_vc_resource (connection ,
104
+ [vim .VirtualMachine ],
105
+ vc_resources [TEMPLATE ])
106
106
if template is None :
107
107
error_msg = (
108
108
"The template: {} does not exist"
109
- " or exception is raised."
109
+ "or exception is raised."
110
110
).format (vc_resources [TEMPLATE ])
111
111
112
112
logger .error (error_msg )
@@ -116,13 +116,13 @@ def create(self, vcip, username, pwd, port, params):
116
116
vc_resources [TEMPLATE ] = template
117
117
118
118
# Check network
119
- network = check_vc_resource (connection ,
120
- [vim .Network ],
121
- vc_resources [NETWORK ])
119
+ network = operation . check_vc_resource (connection ,
120
+ [vim .Network ],
121
+ vc_resources [NETWORK ])
122
122
if network is None :
123
123
error_msg = (
124
- "The network: {} does not exist"
125
- " or exception is raised."
124
+ "The network: {} does not exist, "
125
+ "or exception is raised."
126
126
).format (vc_resources [NETWORK ])
127
127
128
128
logger .error (error_msg )
@@ -131,7 +131,7 @@ def create(self, vcip, username, pwd, port, params):
131
131
else :
132
132
vc_resources [NETWORK ] = network
133
133
134
- create_vm (connection , params )
134
+ operation . create_vm (connection , params )
135
135
return True
136
136
137
137
def delete (self , vmuuid , vcip , username , pwd , port = 443 ):
@@ -144,7 +144,7 @@ def delete(self, vmuuid, vcip, username, pwd, port=443):
144
144
:param port vCenter port
145
145
:return:
146
146
"""
147
- return delete_vm (vcip , username , pwd , port , vmuuid )
147
+ return operation . delete_vm (vcip , username , pwd , port , vmuuid )
148
148
149
149
def reset (self , worker_api , host_type = 'docker' ):
150
150
"""
0 commit comments