def get_runtime_properties(self): xendom = XendDomain.instance() dominfo = xendom.get_vm_by_uuid(self.VM) try: device_dict = {} for device_sxp in dominfo.getDeviceSxprs('vscsi'): target_dev = None for dev in device_sxp[1][0][1]: vdev = sxp.child_value(dev, 'v-dev') if vdev == self.virtual_HCTL: target_dev = dev break if target_dev is None: continue dev_dict = {} for info in target_dev[1:]: dev_dict[info[0]] = info[1] device_dict['dev'] = dev_dict for info in device_sxp[1][1:]: device_dict[info[0]] = info[1] return device_dict except Exception, exn: log.exception(exn) return {}
def save(fd, dominfo, live): write_exact(fd, SIGNATURE, "could not write guest state file: signature") config = sxp.to_string(dominfo.sxpr()) domain_name = dominfo.getName() # Rename the domain temporarily, so that we don't get a name clash if this # domain is migrating (live or non-live) to the local host. Doing such a # thing is useful for debugging. dominfo.setName('migrating-' + domain_name) try: write_exact(fd, pack("!i", len(config)), "could not write guest state file: config len") write_exact(fd, config, "could not write guest state file: config") # xc_save takes three customization parameters: maxit, max_f, and # flags the last controls whether or not save is 'live', while the # first two further customize behaviour when 'live' save is # enabled. Passing "0" simply uses the defaults compiled into # libxenguest; see the comments and/or code in xc_linux_save() for # more information. cmd = [xen.util.auxbin.pathTo(XC_SAVE), str(xc.handle()), str(fd), str(dominfo.getDomid()), "0", "0", str(int(live)) ] log.debug("[xc_save]: %s", string.join(cmd)) def saveInputHandler(line, tochild): log.debug("In saveInputHandler %s", line) if line == "suspend": log.debug("Suspending %d ...", dominfo.getDomid()) dominfo.shutdown('suspend') dominfo.waitForShutdown() log.info("Domain %d suspended.", dominfo.getDomid()) tochild.write("done\n") tochild.flush() log.debug('Written done') forkHelper(cmd, fd, saveInputHandler, False) dominfo.destroyDomain() except Exception, exn: log.exception("Save failed on domain %s (%d).", domain_name, dominfo.getDomid()) try: dominfo.setName(domain_name) except: log.exception("Failed to reset the migrating domain's name") raise Exception, exn
def create(self, dscsi_struct): # Check if VM is valid xendom = XendDomain.instance() if not xendom.is_valid_vm(dscsi_struct['VM']): raise InvalidHandleError('VM', dscsi_struct['VM']) dom = xendom.get_vm_by_uuid(dscsi_struct['VM']) # Check if PSCSI is valid xennode = XendNode.instance() pscsi_uuid = xennode.get_pscsi_by_uuid(dscsi_struct['PSCSI']) if not pscsi_uuid: raise InvalidHandleError('PSCSI', dscsi_struct['PSCSI']) # Assign PSCSI to VM try: dscsi_ref = XendTask.log_progress(0, 100, \ dom.create_dscsi, \ dscsi_struct) except XendError, e: log.exception("Error in create_dscsi") raise
def xen_rpc_call(ip, method, *args): """wrap rpc call to a remote host""" try: if not ip: raise Exception, "Invalid ip for rpc call" # create proxy = ServerProxy("http://" + ip + ":9363/") # login response = proxy.session.login('root') if cmp(response['Status'], 'Failure') == 0: log.exception(response['ErrorDescription']) raise Exception, response['ErrorDescription'] session_ref = response['Value'] # excute method_parts = method.split('_') method_class = method_parts[0] method_name = '_'.join(method_parts[1:]) if method.find("host_metrics") == 0: method_class = "host_metrics" method_name = '_'.join(method_parts[2:]) #log.debug(method_class) #log.debug(method_name) if method_class.find("Async") == 0: method_class = method_class.split(".")[1] response = proxy.__getattr__("Async").__getattr__(method_class).__getattr__(method_name)(session_ref, *args) else: response = proxy.__getattr__(method_class).__getattr__(method_name)(session_ref, *args) if cmp(response['Status'], 'Failure') == 0: log.exception(response['ErrorDescription']) raise Exception, response['ErrorDescription'] # result return response.get('Value') except socket.error: raise Exception, 'socket error'