-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #908 from QualiSystems/develop
Merge dev to master for 1.11.0 release
- Loading branch information
Showing
26 changed files
with
536 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import traceback | ||
import time | ||
|
||
from cloudshell.cp.vcenter.vm.vm_details_provider import VmDetails, VmDataField | ||
|
||
|
||
class VmDetailsCommand(object): | ||
def __init__(self, pyvmomi_service, vm_details_provider): | ||
self.pyvmomi_service = pyvmomi_service | ||
self.vm_details_provider = vm_details_provider | ||
self.timeout = 30 | ||
self.delay = 1 | ||
|
||
def get_vm_details(self, si, logger, resource_context, requests, cancellation_context): | ||
results = [] | ||
for request in requests: | ||
if cancellation_context.is_cancelled: | ||
break | ||
app_name = request.deployedAppJson.name | ||
try: | ||
vm = self.pyvmomi_service.find_by_uuid(si, request.deployedAppJson.vmdetails.uid) | ||
self._wait_for_vm_to_be_ready(vm, request, logger) | ||
result = self.vm_details_provider.create( | ||
vm=vm, | ||
name=app_name, | ||
reserved_networks=resource_context.attributes.get('Reserved Networks', '').split(';'), | ||
ip_regex=next((p.value for p in request.deployedAppJson.vmdetails.vmCustomParams if p.name=='ip_regex'), None), | ||
deployment_details_provider=DeploymentDetailsProviderFromAppJson(request.appRequestJson.deploymentService), | ||
logger=logger) | ||
except Exception as e: | ||
logger.error("Error getting vm details for '{0}': {1}".format(app_name, traceback.format_exc())) | ||
result = VmDetails(app_name) | ||
result.error = e.message | ||
|
||
results.append(result) | ||
|
||
return results | ||
|
||
def _wait_for_vm_to_be_ready(self, vm, request, logger): | ||
start_time = time.time() | ||
while time.time()-start_time<self.timeout and (self._not_guest_net(vm) or self._no_guest_ip(vm, request)): | ||
time.sleep(self.delay) | ||
logger.info('_wait_for_vm_to_be_ready: '+str(time.time()-start_time)+' sec') | ||
|
||
@staticmethod | ||
def _not_guest_net(vm): | ||
return not vm.guest.net | ||
|
||
@staticmethod | ||
def _no_guest_ip(vm, request): | ||
wait_for_ip = next((p.value for p in request.deployedAppJson.vmdetails.vmCustomParams if p.name == 'wait_for_ip'), False) | ||
return wait_for_ip and not vm.guest.ipAddress | ||
|
||
|
||
class DeploymentDetailsProviderFromAppJson(object): | ||
def __init__(self, deployment_service): | ||
self.deployment = deployment_service.model | ||
self.dep_attributes = dict((att.name, att.value) for att in deployment_service.attributes) | ||
|
||
def get_details(self): | ||
""" | ||
:rtype list[VmDataField] | ||
""" | ||
data = [] | ||
if self.deployment == 'vCenter Clone VM From VM': | ||
data.append(VmDataField('Cloned VM Name', self.dep_attributes.get('vCenter VM', ''))) | ||
|
||
if self.deployment == 'VCenter Deploy VM From Linked Clone': | ||
template = self.dep_attributes.get('vCenter VM', '') | ||
snapshot = self.dep_attributes.get('vCenter VM Snapshot', '') | ||
data.append(VmDataField('Cloned VM Name', '{0} (snapshot: {1})'.format(template, snapshot))) | ||
|
||
if self.deployment == 'vCenter VM From Image': | ||
data.append(VmDataField('Base Image Name', self.dep_attributes.get('vCenter Image', '').split('/')[-1])) | ||
|
||
if self.deployment == 'vCenter VM From Template': | ||
data.append(VmDataField('Template Name', self.dep_attributes.get('vCenter Template', ''))) | ||
|
||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.