1212 VC_DATASTORE , VC_DATACENTER , NETWORK , TEMPLATE , VC_CLUSTER
1313
1414from agent import reset_container_host , check_daemon , \
15- create_vm , delete_vm , check_vc_resource , \
16- initializesi
15+ VsphereOperation
1716
1817from ..host_base import HostBase
1918
2019logger = logging .getLogger (__name__ )
2120logger .setLevel (LOG_LEVEL )
2221logger .addHandler (log_handler )
22+ operation = VsphereOperation ()
2323
2424
2525class VsphereHost (HostBase ):
@@ -40,25 +40,25 @@ def create(self, vcip, username, pwd, port, params):
4040 """
4141 # Init connection
4242 try :
43- si = initializesi (vcip , username , pwd , port )
43+ si = operation . initializesi (vcip , username , pwd , port )
4444 connection = si .RetrieveContent ()
4545 vc_resources = params .get (VCENTER )
4646
4747 except Exception as e :
4848 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."
5151 )
5252 raise Exception (error_msg )
5353
5454 # 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 ])
5858 if cluster is None :
5959 error_msg = (
6060 "The Cluster: {} does not exist"
61- " or exception is raised."
61+ "or exception is raised."
6262 ).format (vc_resources [VC_CLUSTER ])
6363
6464 logger .error (error_msg )
@@ -68,13 +68,13 @@ def create(self, vcip, username, pwd, port, params):
6868 vc_resources [VC_CLUSTER ] = cluster
6969
7070 # 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 ])
7474 if datacenter is None :
7575 error_msg = (
76- "The DataCenter: {} does not exist"
77- " or exception is raised."
76+ "The DataCenter: {} does not exist, "
77+ "or exception is raised."
7878 ).format (vc_resources [VC_DATACENTER ])
7979
8080 logger .error (error_msg )
@@ -84,13 +84,13 @@ def create(self, vcip, username, pwd, port, params):
8484 vc_resources [VC_DATACENTER ] = datacenter
8585
8686 # 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 ])
9090 if datastore is None :
9191 error_msg = (
92- "The Datastore: {} does not exist"
93- " or exception is raised."
92+ "The Datastore: {} does not exist, "
93+ "or exception is raised."
9494 ).format (vc_resources [VC_DATASTORE ])
9595
9696 logger .error (error_msg )
@@ -100,13 +100,13 @@ def create(self, vcip, username, pwd, port, params):
100100 vc_resources [VC_DATASTORE ] = datastore
101101
102102 # 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 ])
106106 if template is None :
107107 error_msg = (
108108 "The template: {} does not exist"
109- " or exception is raised."
109+ "or exception is raised."
110110 ).format (vc_resources [TEMPLATE ])
111111
112112 logger .error (error_msg )
@@ -116,13 +116,13 @@ def create(self, vcip, username, pwd, port, params):
116116 vc_resources [TEMPLATE ] = template
117117
118118 # 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 ])
122122 if network is None :
123123 error_msg = (
124- "The network: {} does not exist"
125- " or exception is raised."
124+ "The network: {} does not exist, "
125+ "or exception is raised."
126126 ).format (vc_resources [NETWORK ])
127127
128128 logger .error (error_msg )
@@ -131,7 +131,7 @@ def create(self, vcip, username, pwd, port, params):
131131 else :
132132 vc_resources [NETWORK ] = network
133133
134- create_vm (connection , params )
134+ operation . create_vm (connection , params )
135135 return True
136136
137137 def delete (self , vmuuid , vcip , username , pwd , port = 443 ):
@@ -144,7 +144,7 @@ def delete(self, vmuuid, vcip, username, pwd, port=443):
144144 :param port vCenter port
145145 :return:
146146 """
147- return delete_vm (vcip , username , pwd , port , vmuuid )
147+ return operation . delete_vm (vcip , username , pwd , port , vmuuid )
148148
149149 def reset (self , worker_api , host_type = 'docker' ):
150150 """
0 commit comments