def add_virtual_router(deployConfig, session_uuid, l3_name = None, \ zone_name = None): if not xmlobject.has_element(deployConfig, 'instanceOfferings.virtualRouterOffering'): return for i in xmlobject.safe_list(deployConfig.instanceOfferings.virtualRouterOffering): if l3_name and l3_name != i.managementL3NetworkRef.text_: continue if zone_name and zone_name != i.zoneRef.text_: continue print "continue l3_name: %s; zone_name: %s" % (l3_name, zone_name) action = api_actions.CreateVirtualRouterOfferingAction() action.sessionUuid = session_uuid action.name = i.name_ action.description = i.description__ action.cpuNum = i.cpuNum_ action.cpuSpeed = i.cpuSpeed_ if i.memorySize__: action.memorySize = sizeunit.get_size(i.memorySize_) elif i.memoryCapacity_: action.memorySize = sizeunit.get_size(i.memoryCapacity_) action.isDefault = i.isDefault__ action.type = 'VirtualRouter' zinvs = res_ops.get_resource(res_ops.ZONE, session_uuid, name=i.zoneRef.text_) zinv = get_first_item_from_list(zinvs, 'zone', i.zoneRef.text_, 'virtual router offering') action.zoneUuid = zinv.uuid cond = res_ops.gen_query_conditions('zoneUuid', '=', zinv.uuid) cond1 = res_ops.gen_query_conditions('name', '=', \ i.managementL3NetworkRef.text_, cond) minvs = res_ops.query_resource(res_ops.L3_NETWORK, cond1, \ session_uuid) minv = get_first_item_from_list(minvs, 'Management L3 Network', i.managementL3NetworkRef.text_, 'virtualRouterOffering') action.managementNetworkUuid = minv.uuid if xmlobject.has_element(i, 'publicL3NetworkRef'): cond1 = res_ops.gen_query_conditions('name', '=', \ i.publicL3NetworkRef.text_, cond) pinvs = res_ops.query_resource(res_ops.L3_NETWORK, cond1, \ session_uuid) pinv = get_first_item_from_list(pinvs, 'Public L3 Network', i.publicL3NetworkRef.text_, 'virtualRouterOffering') action.publicNetworkUuid = pinv.uuid iinvs = res_ops.get_resource(res_ops.IMAGE, session_uuid, \ name=i.imageRef.text_) iinv = get_first_item_from_list(iinvs, 'Image', i.imageRef.text_, 'virtualRouterOffering') action.imageUuid = iinv.uuid thread = threading.Thread(target = _thread_for_action, args = (action, )) wait_for_thread_queue() thread.start() wait_for_thread_done()
def get_instance_offering(xml_root, session_uuid=None): cond = [] vr_inst_offerings = res_ops.safely_get_resource(res_ops.VR_OFFERING, cond, \ session_uuid) if vr_inst_offerings: vr_offering_uuids = res_ops.safely_get_resource(res_ops.VR_OFFERING, \ [], session_uuid, ['uuid']) else: return uuids = '' for vr_uuid in vr_offering_uuids: uuids += ' %s' % vr_uuid.uuid cond = res_ops.gen_query_conditions('uuid', 'not in', uuids) inst_offerings = res_ops.safely_get_resource(res_ops.INSTANCE_OFFERING, \ cond, session_uuid) if vr_inst_offerings or inst_offerings: xml_item = etree.SubElement(xml_root, "instanceOfferings") add_xml_items(inst_offerings, 'instanceOffering', xml_item) for vr_offering in vr_inst_offerings: vr_offering_xml_obj = JsonToXml( vr_offering, 'virtualRouterOffering', xml_item, 'managementNetworkUuid \ publicNetworkUuid zoneUuid imageUuid') vr_offering_xml = vr_offering_xml_obj.generate_xml() zone_uuid = vr_offering.zoneUuid cond = res_ops.gen_query_conditions('uuid', '=', zone_uuid) zone_name = res_ops.query_resource(res_ops.ZONE, cond, \ session_uuid)[0].name _set_res_ref(vr_offering_xml, 'zoneRef', zone_name) pub_l3_uuid = vr_offering.publicNetworkUuid cond = res_ops.gen_query_conditions('uuid', '=', pub_l3_uuid) l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond, \ session_uuid)[0].name _set_res_ref(vr_offering_xml, 'publicL3NetworkRef', l3_name) mgt_l3_uuid = vr_offering.managementNetworkUuid cond = res_ops.gen_query_conditions('uuid', '=', mgt_l3_uuid) l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond, \ session_uuid)[0].name _set_res_ref(vr_offering_xml, 'managementL3NetworkRef', l3_name) img_uuid = vr_offering.imageUuid cond = res_ops.gen_query_conditions('uuid', '=', img_uuid) img_name = res_ops.query_resource(res_ops.IMAGE, cond, \ session_uuid)[0].name _set_res_ref(vr_offering_xml, 'imageRef', img_name) return xml_item
def get_instance_offering(xml_root, session_uuid = None): cond = [] vr_inst_offerings = res_ops.safely_get_resource(res_ops.VR_OFFERING, cond, \ session_uuid) if vr_inst_offerings: vr_offering_uuids = res_ops.safely_get_resource(res_ops.VR_OFFERING, \ [], session_uuid, ['uuid']) else: return uuids = '' for vr_uuid in vr_offering_uuids: uuids += ' %s' % vr_uuid.uuid cond = res_ops.gen_query_conditions('uuid', 'not in', uuids) inst_offerings = res_ops.safely_get_resource(res_ops.INSTANCE_OFFERING, \ cond, session_uuid) if vr_inst_offerings or inst_offerings: xml_item = etree.SubElement(xml_root, "instanceOfferings") add_xml_items(inst_offerings, 'instanceOffering', xml_item) for vr_offering in vr_inst_offerings: vr_offering_xml_obj = JsonToXml(vr_offering, 'virtualRouterOffering', xml_item, 'managementNetworkUuid \ publicNetworkUuid zoneUuid imageUuid') vr_offering_xml = vr_offering_xml_obj.generate_xml() zone_uuid = vr_offering.zoneUuid cond = res_ops.gen_query_conditions('uuid', '=', zone_uuid) zone_name = res_ops.query_resource(res_ops.ZONE, cond, \ session_uuid)[0].name _set_res_ref(vr_offering_xml, 'zoneRef', zone_name) pub_l3_uuid = vr_offering.publicNetworkUuid cond = res_ops.gen_query_conditions('uuid', '=', pub_l3_uuid) l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond, \ session_uuid)[0].name _set_res_ref(vr_offering_xml, 'publicL3NetworkRef', l3_name) mgt_l3_uuid = vr_offering.managementNetworkUuid cond = res_ops.gen_query_conditions('uuid', '=', mgt_l3_uuid) l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond, \ session_uuid)[0].name _set_res_ref(vr_offering_xml, 'managementL3NetworkRef', l3_name) img_uuid = vr_offering.imageUuid cond = res_ops.gen_query_conditions('uuid', '=', img_uuid) img_name = res_ops.query_resource(res_ops.IMAGE, cond, \ session_uuid)[0].name _set_res_ref(vr_offering_xml, 'imageRef', img_name) return xml_item
def get_image(xml_root, session_uuid=None): cond = [] images = res_ops.safely_get_resource(res_ops.IMAGE, cond, session_uuid) if images: xml_item = etree.SubElement(xml_root, "images") else: return None for image in images: json_to_xml = JsonToXml(image, 'image', xml_item, 'md5Sum, size') xml_image = json_to_xml.generate_xml() bss = image.backupStorageRefs for bs in bss: bs_uuid = bs.backupStorageUuid cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid) bs_name = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond, \ session_uuid)[0].name _set_backup_strorage_ref(xml_image, bs_name) return xml_item
def get_image(xml_root, session_uuid = None): cond = [] images = res_ops.safely_get_resource(res_ops.IMAGE, cond, session_uuid) if images: xml_item = etree.SubElement(xml_root, "images") else: return None for image in images: json_to_xml = JsonToXml(image, 'image', xml_item, 'md5Sum, size') xml_image = json_to_xml.generate_xml() bss = image.backupStorageRefs for bs in bss: bs_uuid = bs.backupStorageUuid cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid) bs_name = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond, \ session_uuid)[0].name _set_backup_strorage_ref(xml_image, bs_name) return xml_item