def extract_vif(self, vif_sxp, document): vif = document.createElement("vif") dev = get_child_by_name(vif_sxp, "vifname", None) if dev is None: dev = self.getFreshEthDevice() vif.attributes["name"] \ = "vif" + str(dev.__hash__()) vif.attributes["mac"] \ = get_child_by_name(vif_sxp, "mac", "") vif.attributes["mtu"] \ = get_child_by_name(vif_sxp, "mtu", "") vif.attributes["device"] = dev vif.attributes["qos_algorithm_type"] = "" policy = get_child_by_name(vif_sxp, "policy") label = get_child_by_name(vif_sxp, "label") vif.attributes["security_label"] = security.set_security_label( policy, label) if get_child_by_name(vif_sxp, "bridge") is not None: vif.attributes["network"] \ = get_child_by_name(vif_sxp, "bridge") return vif
def extract_vif(self, vif_sxp, document): vif = document.createElement("vif") dev = get_child_by_name(vif_sxp, "vifname", None) if dev is None: dev = self.getFreshEthDevice() vif.attributes["name"] \ = "vif" + str(dev.__hash__()) vif.attributes["mac"] \ = get_child_by_name(vif_sxp, "mac", "") vif.attributes["mtu"] \ = get_child_by_name(vif_sxp, "mtu", "") vif.attributes["device"] = dev vif.attributes["qos_algorithm_type"] = "" policy = get_child_by_name(vif_sxp, "policy") label = get_child_by_name(vif_sxp, "label") vif.attributes["security_label"] = security.set_security_label(policy, label) if get_child_by_name(vif_sxp, "bridge") is not None: vif.attributes["network"] \ = get_child_by_name(vif_sxp, "bridge") return vif
def convert_sxp_to_xml(self, config, transient=False): devices = [ child for child in sxp.children(config) if len(child) > 0 and child[0] == "device" ] vbds_sxp = map(lambda x: x[1], [device for device in devices if device[1][0] == "vbd"]) vifs_sxp = map(lambda x: x[1], [device for device in devices if device[1][0] == "vif"]) vtpms_sxp = map( lambda x: x[1], [device for device in devices if device[1][0] == "vtpm"]) # Create XML Document impl = getDOMImplementation() document = impl.createDocument(None, "xm", None) # Lets make the VM tag.. vm = document.createElement("vm") # Some string compatibility actions_after_shutdown \ = get_child_by_name(config, "on_poweroff", "destroy") actions_after_reboot \ = get_child_by_name(config, "on_reboot", "restart") actions_after_crash \ = get_child_by_name(config, "on_crash", "restart") def conv_chk(val, vals): val.replace("-", "_") if val not in vals: raise "Invalid value: " + val else: return val actions_after_shutdown = conv_chk(actions_after_shutdown,\ XEN_API_ON_NORMAL_EXIT) actions_after_reboot = conv_chk(actions_after_reboot, \ XEN_API_ON_NORMAL_EXIT) actions_after_crash = conv_chk(actions_after_crash, \ XEN_API_ON_CRASH_BEHAVIOUR) # Flesh out tag attributes vm.attributes["is_a_template"] = "false" vm.attributes["auto_power_on"] = "false" vm.attributes["actions_after_shutdown"] \ = actions_after_shutdown vm.attributes["actions_after_reboot"] \ = actions_after_reboot vm.attributes["actions_after_crash"] \ = actions_after_crash vm.attributes["PCI_bus"] = "" vm.attributes["vcpus_max"] \ = str(get_child_by_name(config, "vcpus", 1)) vm.attributes["vcpus_at_startup"] \ = str(get_child_by_name(config, "vcpus", 1)) sec_data = get_child_by_name(config, "security") if sec_data: try: vm.attributes['security_label'] = \ security.set_security_label(sec_data[0][1][1],sec_data[0][2][1]) except Exception, e: raise "Invalid security data format: %s" % str(sec_data)
def convert_sxp_to_xml(self, config, transient=False): devices = [child for child in sxp.children(config) if len(child) > 0 and child[0] == "device"] vbds_sxp = map(lambda x: x[1], [device for device in devices if device[1][0] in ("vbd", "tap", "tap2")]) vifs_sxp = map(lambda x: x[1], [device for device in devices if device[1][0] == "vif"]) vtpms_sxp = map(lambda x: x[1], [device for device in devices if device[1][0] == "vtpm"]) vfbs_sxp = map(lambda x: x[1], [device for device in devices if device[1][0] == "vfb"]) pcis_sxp = map(lambda x: x[1], [device for device in devices if device[1][0] == "pci"]) scsis_sxp = map(lambda x: x[1], [device for device in devices if device[1][0] == "vscsi"]) # Create XML Document impl = getDOMImplementation() document = impl.createDocument(None, "xm", None) # Lets make the VM tag.. vm = document.createElement("vm") # Some string compatibility actions_after_shutdown \ = get_child_by_name(config, "on_poweroff", "destroy") actions_after_reboot \ = get_child_by_name(config, "on_reboot", "restart") actions_after_crash \ = get_child_by_name(config, "on_crash", "restart") def conv_chk(val, vals): lval = val.replace("-", "_") if lval not in vals: raise ValueError("Invalid value: %s" % val) else: return lval actions_after_shutdown = conv_chk(actions_after_shutdown,\ XEN_API_ON_NORMAL_EXIT) actions_after_reboot = conv_chk(actions_after_reboot, \ XEN_API_ON_NORMAL_EXIT) actions_after_crash = conv_chk(actions_after_crash, \ XEN_API_ON_CRASH_BEHAVIOUR) # Flesh out tag attributes vm.attributes["is_a_template"] = "false" vm.attributes["auto_power_on"] = "false" vm.attributes["actions_after_shutdown"] \ = actions_after_shutdown vm.attributes["actions_after_reboot"] \ = actions_after_reboot vm.attributes["actions_after_crash"] \ = actions_after_crash vm.attributes["PCI_bus"] = "" vm.attributes["vcpus_max"] \ = str(get_child_by_name(config, "vcpus", 1)) vm.attributes["vcpus_at_startup"] \ = str(get_child_by_name(config, "vcpus", 1)) vm.attributes["s3_integrity"] \ = str(get_child_by_name(config, "s3_integrity", 0)) vm.attributes["superpages"] \ = str(get_child_by_name(config, "superpages", 0)) sec_data = get_child_by_name(config, "security") if sec_data: try : vm.attributes['security_label'] = \ security.set_security_label(sec_data[0][1][1],sec_data[0][2][1]) except Exception, e: raise "Invalid security data format: %s" % str(sec_data)