def provision_vm(self, auth, managed_node, image_id, v_config, i_config): external_id = None client = self.get_client(managed_node) name = v_config.name compute_resource = v_config.get('compute_resource') disks = v_config.getDisks(i_config) nics = v_config.getNetworks(i_config) print '------nics--------', print nics memory = v_config.get('memory') cpus = v_config.get('vcpus') guest_id = v_config.get('guest_id') if not guest_id: msg = 'guest_id not specified in miscellaneous tab of selected template. Example:ubuntu64Guest' LOGGER.error(msg) raise Exception(msg) host = None if not compute_resource: os_info = managed_node.get_os_info() if os_info: host = os_info.get('node_name') print '--compute_resource---host--', print compute_resource, print host try: task_result = self.create_vm(client, name, compute_resource, nics, memory, cpus, guest_id, host, disks) if not task_result['success']: return (task_result['msg'], self.FAILED, self.LOG_FILE, external_id) vm_mob = task_result['result'] if not vm_mob: raise Exception('Could not find VirtualMachine managedobject') external_id = get_moid(vm_mob) managed_node.node_proxy.update_vms() return (task_result['msg'], self.SUCCESS, self.LOG_FILE, external_id) except Exception as ex: traceback.print_stack() msg = str(ex) return (msg, self.FAILED, self.LOG_FILE, external_id) return None
def provision_vm(self, auth, managed_node, image_id, v_config, i_config): from stackone.model import DBSession from stackone.model.ImageStore import Image external_id = None image = DBSession.query(Image).filter(Image.id == image_id).first() client = self.get_client(managed_node) config_context = {} config_context['dest_datastore'] = v_config.get('datastore') config_context['dest_host'] = managed_node.hostname config_context['name'] = v_config.get('name') config_context['vmfolder'] = v_config.get('vmfolder') config_context['mob_name'] = image.name disks = v_config.getDisks(i_config) config_context['disks'] = disks task_result = self.clone_to(client, v_config, config_context=config_context) if not task_result['success']: return (task_result['msg'], self.FAILED, self.LOG_FILE, external_id) vm_mob = task_result['result'] if not vm_mob: raise Exception('Could not find VirtualMachine managedobject') external_id = get_moid(vm_mob) return (task_result['msg'], self.SUCCESS, self.LOG_FILE, external_id)
def get_external_id(self): from stackone.core.utils.VMWUtils import get_moid hs = self.node_proxy.get_hs() return get_moid(hs)
def get_moid(cls, instance): from stackone.core.utils.VMWUtils import get_moid return get_moid(instance)