Example #1
0
def get_backup_storage(xml_root, session_uuid = None):
    cond = []
    bs_storages = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE, cond, \
            session_uuid)

    if bs_storages:
        xml_item = etree.SubElement(xml_root, "backupStorages")
    else:
        return None
    
    sftp_bs_storages = res_ops.safely_get_resource(res_ops.SFTP_BACKUP_STORAGE,\
            cond, session_uuid)

    if sftp_bs_storages:
        add_xml_items(sftp_bs_storages, 'sftpBackupStorage', xml_item, \
                'attachedZoneUuids availableCapacity totalCapacity')

    cond = res_ops.gen_query_conditions('type', '=', 'SimulatorBackupStorage')
    simulator_bss = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE, \
            cond, session_uuid)

    if simulator_bss:
        add_xml_items(simulator_bss, 'simulatorBackupStorage', xml_item, \
                'attachedZoneUuids')

    return xml_item
Example #2
0
    def _get_cluster(clusters_xml, clusters):
        for cluster in clusters:
            cluster_xml_obj = JsonToXml(cluster, 'cluster', clusters_xml)
            cluster_xml = cluster_xml_obj.generate_xml()

            #add_hosts
            cond = res_ops.gen_query_conditions('clusterUuid', '=', \
                    cluster.uuid)
            hosts = res_ops.safely_get_resource(res_ops.HOST, cond, \
                    session_uuid)
            if hosts:
                hosts_xml = etree.SubElement(cluster_xml, "hosts")
                add_xml_items(hosts, 'host', hosts_xml, \
                        'availableCpuCapacity availableMemoryCapacity \
                        clusterUuid hypervisorType totalCpuCapacity \
                        totalMemoryCapacity zoneUuid')
            
            #add ps ref
            cond = res_ops.gen_query_conditions('attachedClusterUuids', 'in', \
                    cluster.uuid)
            pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                    session_uuid, fields=['name'])

            for ps in pss:
                _set_primary_strorage_ref(cluster_xml, ps.name)


            #add l2 ref
            cond = res_ops.gen_query_conditions('attachedClusterUuids', 'in', \
                    cluster.uuid)
            l2s = res_ops.safely_get_resource(res_ops.L2_NETWORK, cond, 
                    session_uuid, fields=['name'])

            for l2 in l2s:
                _set_l2_ref(cluster_xml, l2.name)
Example #3
0
    def _get_primary_storage(pss_xml, zone):
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        for ps in pss:
            if ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE:
                json_to_xml = JsonToXml(bs, 'nfsPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid')
                json_to_xml.generate_xml()
            elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:
                json_to_xml = JsonToXml(bs, 'cephPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid')
                json_to_xml.generate_xml()
            elif ps.type == inventory.LOCAL_STORAGE_TYPE:
                json_to_xml = JsonToXml(bs, 'localPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid')
                json_to_xml.generate_xml()

        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        cond = res_ops.gen_query_conditions('type', '=', \
                'SimulatorPrimaryStorage', cond)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        add_xml_items(pss, 'simulatorPrimaryStorage', pss_xml, \
                'mountPath type zoneUuid')
Example #4
0
def get_backup_storage(xml_root, session_uuid=None):
    cond = []
    bs_storages = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE, cond, \
            session_uuid)

    if bs_storages:
        xml_item = etree.SubElement(xml_root, "backupStorages")
    else:
        return None

    bs_storages = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE,\
            cond, session_uuid)

    for bs in bs_storages:
        if bs.type == inventory.SFTP_BACKUP_STORAGE_TYPE:
            json_to_xml = JsonToXml(bs, 'sftpBackupStorage', xml_item, \
                   'attachedZoneUuids availableCapacity totalCapacity')
            json_to_xml.generate_xml()
        elif bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE:
            json_to_xml = JsonToXml(bs, 'cephBackupStorage', xml_item, \
                   'attachedZoneUuids availableCapacity totalCapacity')
            json_to_xml.generate_xml()

    cond = res_ops.gen_query_conditions('type', '=', 'SimulatorBackupStorage')
    simulator_bss = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE, \
            cond, session_uuid)

    if simulator_bss:
        add_xml_items(simulator_bss, 'simulatorBackupStorage', xml_item, \
                'attachedZoneUuids')

    return xml_item
Example #5
0
def get_backup_storage(xml_root, session_uuid=None):
    cond = []
    bs_storages = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE, cond, \
            session_uuid)

    if bs_storages:
        xml_item = etree.SubElement(xml_root, "backupStorages")
    else:
        return None

    sftp_bs_storages = res_ops.safely_get_resource(res_ops.SFTP_BACKUP_STORAGE,\
            cond, session_uuid)

    if sftp_bs_storages:
        add_xml_items(sftp_bs_storages, 'sftpBackupStorage', xml_item, \
                'attachedZoneUuids availableCapacity totalCapacity')

    cond = res_ops.gen_query_conditions('type', '=', 'SimulatorBackupStorage')
    simulator_bss = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE, \
            cond, session_uuid)

    if simulator_bss:
        add_xml_items(simulator_bss, 'simulatorBackupStorage', xml_item, \
                'attachedZoneUuids')

    return xml_item
Example #6
0
def get_backup_storage(xml_root, session_uuid = None):
    cond = []
    bs_storages = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE, cond, \
            session_uuid)

    if bs_storages:
        xml_item = etree.SubElement(xml_root, "backupStorages")
    else:
        return None
    
    bs_storages = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE,\
            cond, session_uuid)

    for bs in bs_storages:
        if bs.type == inventory.SFTP_BACKUP_STORAGE_TYPE:
       	    json_to_xml = JsonToXml(bs, 'sftpBackupStorage', xml_item, \
                   'attachedZoneUuids availableCapacity totalCapacity')
            json_to_xml.generate_xml()
        elif bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE:
       	    json_to_xml = JsonToXml(bs, 'cephBackupStorage', xml_item, \
                   'attachedZoneUuids availableCapacity totalCapacity')
            json_to_xml.generate_xml()

    cond = res_ops.gen_query_conditions('type', '=', 'SimulatorBackupStorage')
    simulator_bss = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE, \
            cond, session_uuid)

    if simulator_bss:
        add_xml_items(simulator_bss, 'simulatorBackupStorage', xml_item, \
                'attachedZoneUuids')

    return xml_item
Example #7
0
    def _get_cluster(clusters_xml, clusters):
        for cluster in clusters:
            cluster_xml_obj = JsonToXml(cluster, 'cluster', clusters_xml)
            cluster_xml = cluster_xml_obj.generate_xml()

            #add_hosts
            cond = res_ops.gen_query_conditions('clusterUuid', '=', \
                    cluster.uuid)
            hosts = res_ops.safely_get_resource(res_ops.HOST, cond, \
                    session_uuid)
            if hosts:
                hosts_xml = etree.SubElement(cluster_xml, "hosts")
                add_xml_items(hosts, 'host', hosts_xml, \
                        'availableCpuCapacity availableMemoryCapacity \
                        clusterUuid hypervisorType totalCpuCapacity \
                        totalMemoryCapacity zoneUuid')
            
            #add ps ref
            cond = res_ops.gen_query_conditions('attachedClusterUuids', 'in', \
                    cluster.uuid)
            pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                    session_uuid, fields=['name'])

            for ps in pss:
                _set_primary_strorage_ref(cluster_xml, ps.name)


            #add l2 ref
            cond = res_ops.gen_query_conditions('attachedClusterUuids', 'in', \
                    cluster.uuid)
            l2s = res_ops.safely_get_resource(res_ops.L2_NETWORK, cond, 
                    session_uuid, fields=['name'])

            for l2 in l2s:
                _set_l2_ref(cluster_xml, l2.name)
Example #8
0
    def _get_primary_storage(pss_xml, zone):
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        for ps in pss:
            if ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE:
       	        json_to_xml = JsonToXml(ps, 'nfsPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid totalPhysicalCapacity')
                json_to_xml.generate_xml()
            elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:
       	        json_to_xml = JsonToXml(ps, 'cephPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid totalPhysicalCapacity')
                json_to_xml.generate_xml()
            elif ps.type == inventory.LOCAL_STORAGE_TYPE:
       	        json_to_xml = JsonToXml(ps, 'localPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid totalPhysicalCapacity')
                json_to_xml.generate_xml()

        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        cond = res_ops.gen_query_conditions('type', '=', \
                'SimulatorPrimaryStorage', cond)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        add_xml_items(pss, 'simulatorPrimaryStorage', pss_xml, \
                'mountPath type zoneUuid')
Example #9
0
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
Example #10
0
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
Example #11
0
    def _add_l3(l2_xml, l2):
        #basic
        cond = res_ops.gen_query_conditions('l2NetworkUuid', '=', l2.uuid)
        cond = res_ops.gen_query_conditions('type', '=', 'L3BasicNetwork',
                                            cond)
        l3s = res_ops.safely_get_resource(res_ops.L3_NETWORK, cond,
                                          session_uuid)
        if not l3s:
            return None

        l3s_xml = etree.SubElement(l2_xml, "l3Networks")
        for l3 in l3s:
            l3_xml_obj = JsonToXml(l3, 'l3BasicNetwork', l3s_xml, \
                    'type zoneUuid l2NetworkUuid')
            l3_xml = l3_xml_obj.generate_xml()

            #ip range
            cond = res_ops.gen_query_conditions('l3NetworkUuid', '=', l3.uuid)
            ip_ranges = res_ops.safely_get_resource(res_ops.IP_RANGE, cond,
                                                    session_uuid)
            add_xml_items(ip_ranges, 'ipRange', l3_xml, 'l3NetworkUuid')

            #dns
            if l3.dns:
                for dns in l3.dns:
                    dns_xml = etree.SubElement(l3_xml, "dns")
                    dns_xml.text = dns

            #network service
            if l3.networkServices:
                nss_dict = {}
                for ns in l3.networkServices:
                    if not ns.networkServiceProviderUuid in nss_dict.keys():
                        nss_dict[ns.networkServiceProviderUuid] \
                                = [ns.networkServiceType]
                    else:
                        nss_dict[ns.networkServiceProviderUuid].append(
                            ns.networkServiceType)

                for key in nss_dict.keys():
                    cond = res_ops.gen_query_conditions('uuid', '=', key)
                    ns = res_ops.safely_get_resource(\
                            res_ops.NETWORK_SERVICE_PROVIDER, cond, session_uuid)
                    ns_name = ns[0].name

                    ns_xml = etree.SubElement(l3_xml, "networkService")
                    ns_xml.set('provider', ns_name)
                    for value in nss_dict[key]:
                        ns_type_xml = etree.SubElement(ns_xml, 'serviceType')
                        ns_type_xml.text = value
Example #12
0
    def _get_primary_storage(pss_xml, zone):
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        cond = res_ops.gen_query_conditions('type', '=', 'NFS', cond)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        add_xml_items(pss, 'nfsPrimaryStorage', pss_xml, \
                'availableCapacity mountPath totalCapacity type zoneUuid')

        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        cond = res_ops.gen_query_conditions('type', '=', \
                'SimulatorPrimaryStorage', cond)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        add_xml_items(pss, 'simulatorPrimaryStorage', pss_xml, \
                'mountPath type zoneUuid')
Example #13
0
    def _get_primary_storage(pss_xml, zone):
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        cond = res_ops.gen_query_conditions('type', '=', 'NFS', cond)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        add_xml_items(pss, 'nfsPrimaryStorage', pss_xml, \
                'availableCapacity mountPath totalCapacity type zoneUuid')

        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        cond = res_ops.gen_query_conditions('type', '=', \
                'SimulatorPrimaryStorage', cond)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        add_xml_items(pss, 'simulatorPrimaryStorage', pss_xml, \
                'mountPath type zoneUuid')
Example #14
0
    def _add_l3(l2_xml, l2):
        #basic
        cond = res_ops.gen_query_conditions('l2NetworkUuid', '=', l2.uuid)
        cond = res_ops.gen_query_conditions('type', '=', 'L3BasicNetwork', cond)
        l3s = res_ops.safely_get_resource(res_ops.L3_NETWORK, cond, 
                session_uuid)
        if not l3s:
            return None

        l3s_xml = etree.SubElement(l2_xml, "l3Networks")
        for l3 in l3s:
            l3_xml_obj = JsonToXml(l3, 'l3BasicNetwork', l3s_xml, \
                    'type zoneUuid l2NetworkUuid')
            l3_xml = l3_xml_obj.generate_xml()

            #ip range
            cond = res_ops.gen_query_conditions('l3NetworkUuid', '=', l3.uuid)
            ip_ranges = res_ops.safely_get_resource(res_ops.IP_RANGE, cond, 
                    session_uuid)
            add_xml_items(ip_ranges, 'ipRange', l3_xml, 'l3NetworkUuid')

            #dns
            if l3.dns:
                for dns in l3.dns:
                    dns_xml = etree.SubElement(l3_xml, "dns")
                    dns_xml.text = dns

            #network service
            if l3.networkServices:
                nss_dict = {}
                for ns in l3.networkServices:
                    if not ns.networkServiceProviderUuid in nss_dict.keys():
                        nss_dict[ns.networkServiceProviderUuid] \
                                = [ns.networkServiceType]
                    else:
                        nss_dict[ns.networkServiceProviderUuid].append(ns.networkServiceType)

                for key in nss_dict.keys():
                    cond = res_ops.gen_query_conditions('uuid', '=', key)
                    ns = res_ops.safely_get_resource(\
                            res_ops.NETWORK_SERVICE_PROVIDER, cond, session_uuid)
                    ns_name = ns[0].name
    
                    ns_xml = etree.SubElement(l3_xml, "networkService")
                    ns_xml.set('provider', ns_name)
                    for value in nss_dict[key]:
                        ns_type_xml = etree.SubElement(ns_xml, 'serviceType')
                        ns_type_xml.text = value
Example #15
0
def get_node(xml_root, session_uuid = None):
    nodes = res_ops.safely_get_resource(res_ops.MANAGEMENT_NODE, [], \
            session_uuid)
    if nodes:
        xml_nodes = etree.SubElement(xml_root, "nodes")
        add_xml_items(nodes, 'node', xml_nodes, 'heartBeat joinDate')
        return xml_nodes
Example #16
0
def get_node(xml_root, session_uuid=None):
    nodes = res_ops.safely_get_resource(res_ops.MANAGEMENT_NODE, [], \
            session_uuid)
    if nodes:
        xml_nodes = etree.SubElement(xml_root, "nodes")
        add_xml_items(nodes, 'node', xml_nodes, 'heartBeat joinDate')
        return xml_nodes
def get_vm(xml_root, session_uuid=None):
    cond = []
    vms = res_ops.safely_get_resource(res_ops.VM_INSTANCE, cond, session_uuid)

    if vms:
        xml_item = etree.SubElement(xml_root, "vms")
    else:
        return None

    vms = res_ops.safely_get_resource(res_ops.VM_INSTANCE, cond, session_uuid)

    for vm in vms:
        json_to_xml = JsonToXml(vm, 'vm', xml_item, 'allocatorStrategy')
        json_to_xml.generate_xml()

    return xml_item
Example #18
0
def get_disk_offering(xml_root, session_uuid = None):
    cond = []
    disk_offerings = res_ops.safely_get_resource(res_ops.DISK_OFFERING, cond, \
            session_uuid)

    if disk_offerings:
        xml_item = etree.SubElement(xml_root, "diskOfferings")
    else:
        return None

    add_xml_items(disk_offerings, 'diskOffering', xml_item)
    return xml_item
Example #19
0
def get_disk_offering(xml_root, session_uuid=None):
    cond = []
    disk_offerings = res_ops.safely_get_resource(res_ops.DISK_OFFERING, cond, \
            session_uuid)

    if disk_offerings:
        xml_item = etree.SubElement(xml_root, "diskOfferings")
    else:
        return None

    add_xml_items(disk_offerings, 'diskOffering', xml_item)
    return xml_item
Example #20
0
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
Example #21
0
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
Example #22
0
def get_zone(xml_root, session_uuid=None):
    def _get_primary_storage(pss_xml, zone):
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        for ps in pss:
            if ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE:
                json_to_xml = JsonToXml(bs, 'nfsPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid')
                json_to_xml.generate_xml()
            elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:
                json_to_xml = JsonToXml(bs, 'cephPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid')
                json_to_xml.generate_xml()
            elif ps.type == inventory.LOCAL_STORAGE_TYPE:
                json_to_xml = JsonToXml(bs, 'localPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid')
                json_to_xml.generate_xml()

        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        cond = res_ops.gen_query_conditions('type', '=', \
                'SimulatorPrimaryStorage', cond)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        add_xml_items(pss, 'simulatorPrimaryStorage', pss_xml, \
                'mountPath type zoneUuid')

    def _get_cluster(clusters_xml, clusters):
        for cluster in clusters:
            cluster_xml_obj = JsonToXml(cluster, 'cluster', clusters_xml)
            cluster_xml = cluster_xml_obj.generate_xml()

            #add_hosts
            cond = res_ops.gen_query_conditions('clusterUuid', '=', \
                    cluster.uuid)
            hosts = res_ops.safely_get_resource(res_ops.HOST, cond, \
                    session_uuid)
            if hosts:
                hosts_xml = etree.SubElement(cluster_xml, "hosts")
                add_xml_items(hosts, 'host', hosts_xml, \
                        'availableCpuCapacity availableMemoryCapacity \
                        clusterUuid hypervisorType totalCpuCapacity \
                        totalMemoryCapacity zoneUuid'                                                     )

            #add ps ref
            cond = res_ops.gen_query_conditions('attachedClusterUuids', 'in', \
                    cluster.uuid)
            pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                    session_uuid, fields=['name'])

            for ps in pss:
                _set_primary_strorage_ref(cluster_xml, ps.name)

            #add l2 ref
            cond = res_ops.gen_query_conditions('attachedClusterUuids', 'in', \
                    cluster.uuid)
            l2s = res_ops.safely_get_resource(res_ops.L2_NETWORK,
                                              cond,
                                              session_uuid,
                                              fields=['name'])

            for l2 in l2s:
                _set_l2_ref(cluster_xml, l2.name)

    def _add_l3(l2_xml, l2):
        #basic
        cond = res_ops.gen_query_conditions('l2NetworkUuid', '=', l2.uuid)
        cond = res_ops.gen_query_conditions('type', '=', 'L3BasicNetwork',
                                            cond)
        l3s = res_ops.safely_get_resource(res_ops.L3_NETWORK, cond,
                                          session_uuid)
        if not l3s:
            return None

        l3s_xml = etree.SubElement(l2_xml, "l3Networks")
        for l3 in l3s:
            l3_xml_obj = JsonToXml(l3, 'l3BasicNetwork', l3s_xml, \
                    'type zoneUuid l2NetworkUuid')
            l3_xml = l3_xml_obj.generate_xml()

            #ip range
            cond = res_ops.gen_query_conditions('l3NetworkUuid', '=', l3.uuid)
            ip_ranges = res_ops.safely_get_resource(res_ops.IP_RANGE, cond,
                                                    session_uuid)
            add_xml_items(ip_ranges, 'ipRange', l3_xml, 'l3NetworkUuid')

            #dns
            if l3.dns:
                for dns in l3.dns:
                    dns_xml = etree.SubElement(l3_xml, "dns")
                    dns_xml.text = dns

            #network service
            if l3.networkServices:
                nss_dict = {}
                for ns in l3.networkServices:
                    if not ns.networkServiceProviderUuid in nss_dict.keys():
                        nss_dict[ns.networkServiceProviderUuid] \
                                = [ns.networkServiceType]
                    else:
                        nss_dict[ns.networkServiceProviderUuid].append(
                            ns.networkServiceType)

                for key in nss_dict.keys():
                    cond = res_ops.gen_query_conditions('uuid', '=', key)
                    ns = res_ops.safely_get_resource(\
                            res_ops.NETWORK_SERVICE_PROVIDER, cond, session_uuid)
                    ns_name = ns[0].name

                    ns_xml = etree.SubElement(l3_xml, "networkService")
                    ns_xml.set('provider', ns_name)
                    for value in nss_dict[key]:
                        ns_type_xml = etree.SubElement(ns_xml, 'serviceType')
                        ns_type_xml.text = value

    cond = []
    zones = res_ops.safely_get_resource(res_ops.ZONE, cond, session_uuid)

    if not zones:
        return None

    zones_xml = etree.SubElement(xml_root, "zones")

    for zone in zones:
        zone_xml_obj = JsonToXml(zone, 'zone', zones_xml)
        zone_xml = zone_xml_obj.generate_xml()

        #query bs ref
        cond = res_ops.gen_query_conditions('attachedZoneUuids', 'in', \
                zone.uuid)
        bss = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE, cond, \
                session_uuid, fields=['name'])
        for bs in bss:
            _set_backup_strorage_ref(zone_xml, bs.name)

        #query ps
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)

        if pss:
            pss_xml = etree.SubElement(zone_xml, "primaryStorages")
            _get_primary_storage(pss_xml, zone)

        #query cluster
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        clusters = res_ops.safely_get_resource(res_ops.CLUSTER, cond, \
                session_uuid)
        if clusters:
            clusters_xml = etree.SubElement(zone_xml, "clusters")
            _get_cluster(clusters_xml, clusters)

        #add l2
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        l2s = res_ops.safely_get_resource(res_ops.L2_NETWORK, cond, \
                session_uuid)
        if l2s:
            l2s_xml = etree.SubElement(zone_xml, "l2Networks")
            #query no vlan
            cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
            cond = res_ops.gen_query_conditions('type', '=', 'L2NoVlanNetwork')
            l2s_no_vlan = res_ops.safely_get_resource(res_ops.L2_NETWORK, cond,
                                                      session_uuid)

            for l2 in l2s_no_vlan:
                l2_no_vlan_obj = JsonToXml(l2, 'l2NoVlanNetwork', l2s_xml,
                                           'type zoneUuid')
                l2_xml = l2_no_vlan_obj.generate_xml()
                _add_l3(l2_xml, l2)

            #query vlan
            cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
            l2s_vlan = res_ops.safely_get_resource(res_ops.L2_VLAN_NETWORK,
                                                   cond, session_uuid)

            for l2 in l2s_vlan:
                l2_vlan_xml_obj = JsonToXml(l2, 'l2VlanNetwork', l2s_xml,
                                            'type zoneUuid')
                l2_xml = l2_vlan_xml_obj.generate_xml()
                _add_l3(l2_xml, l2)
Example #23
0
def get_zone(xml_root, session_uuid = None):
    def _get_primary_storage(pss_xml, zone):
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        for ps in pss:
            if ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE:
       	        json_to_xml = JsonToXml(ps, 'nfsPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid totalPhysicalCapacity')
                json_to_xml.generate_xml()
            elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:
       	        json_to_xml = JsonToXml(ps, 'cephPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid totalPhysicalCapacity')
                json_to_xml.generate_xml()
            elif ps.type == inventory.LOCAL_STORAGE_TYPE:
       	        json_to_xml = JsonToXml(ps, 'localPrimaryStorage', pss_xml, \
                        'availableCapacity mountPath totalCapacity type zoneUuid totalPhysicalCapacity')
                json_to_xml.generate_xml()

        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        cond = res_ops.gen_query_conditions('type', '=', \
                'SimulatorPrimaryStorage', cond)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)
        add_xml_items(pss, 'simulatorPrimaryStorage', pss_xml, \
                'mountPath type zoneUuid')

    def _get_cluster(clusters_xml, clusters):
        for cluster in clusters:
            cluster_xml_obj = JsonToXml(cluster, 'cluster', clusters_xml)
            cluster_xml = cluster_xml_obj.generate_xml()

            #add_hosts
            cond = res_ops.gen_query_conditions('clusterUuid', '=', \
                    cluster.uuid)
            hosts = res_ops.safely_get_resource(res_ops.HOST, cond, \
                    session_uuid)
            if hosts:
                hosts_xml = etree.SubElement(cluster_xml, "hosts")
                add_xml_items(hosts, 'host', hosts_xml, \
                        'availableCpuCapacity availableMemoryCapacity \
                        clusterUuid hypervisorType totalCpuCapacity \
                        totalMemoryCapacity zoneUuid')
            
            #add ps ref
            cond = res_ops.gen_query_conditions('attachedClusterUuids', 'in', \
                    cluster.uuid)
            pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                    session_uuid, fields=['name'])

            for ps in pss:
                _set_primary_strorage_ref(cluster_xml, ps.name)


            #add l2 ref
            cond = res_ops.gen_query_conditions('attachedClusterUuids', 'in', \
                    cluster.uuid)
            l2s = res_ops.safely_get_resource(res_ops.L2_NETWORK, cond, 
                    session_uuid, fields=['name'])

            for l2 in l2s:
                _set_l2_ref(cluster_xml, l2.name)

    def _add_l3(l2_xml, l2):
        #basic
        cond = res_ops.gen_query_conditions('l2NetworkUuid', '=', l2.uuid)
        cond = res_ops.gen_query_conditions('type', '=', 'L3BasicNetwork', cond)
        l3s = res_ops.safely_get_resource(res_ops.L3_NETWORK, cond, 
                session_uuid)
        if not l3s:
            return None

        l3s_xml = etree.SubElement(l2_xml, "l3Networks")
        for l3 in l3s:
            l3_xml_obj = JsonToXml(l3, 'l3BasicNetwork', l3s_xml, \
                    'type zoneUuid l2NetworkUuid')
            l3_xml = l3_xml_obj.generate_xml()

            #ip range
            cond = res_ops.gen_query_conditions('l3NetworkUuid', '=', l3.uuid)
            ip_ranges = res_ops.safely_get_resource(res_ops.IP_RANGE, cond, 
                    session_uuid)
            add_xml_items(ip_ranges, 'ipRange', l3_xml, 'l3NetworkUuid')

            #dns
            if l3.dns:
                for dns in l3.dns:
                    dns_xml = etree.SubElement(l3_xml, "dns")
                    dns_xml.text = dns

            #network service
            if l3.networkServices:
                nss_dict = {}
                for ns in l3.networkServices:
                    if not ns.networkServiceProviderUuid in nss_dict.keys():
                        nss_dict[ns.networkServiceProviderUuid] \
                                = [ns.networkServiceType]
                    else:
                        nss_dict[ns.networkServiceProviderUuid].append(ns.networkServiceType)

                for key in nss_dict.keys():
                    cond = res_ops.gen_query_conditions('uuid', '=', key)
                    ns = res_ops.safely_get_resource(\
                            res_ops.NETWORK_SERVICE_PROVIDER, cond, session_uuid)
                    ns_name = ns[0].name
    
                    ns_xml = etree.SubElement(l3_xml, "networkService")
                    ns_xml.set('provider', ns_name)
                    for value in nss_dict[key]:
                        ns_type_xml = etree.SubElement(ns_xml, 'serviceType')
                        ns_type_xml.text = value

    cond = []
    zones = res_ops.safely_get_resource(res_ops.ZONE, cond, session_uuid)

    if not zones:
        return None

    zones_xml = etree.SubElement(xml_root, "zones")

    for zone in zones:
        zone_xml_obj = JsonToXml(zone, 'zone', zones_xml)
        zone_xml = zone_xml_obj.generate_xml()

        #query bs ref
        cond = res_ops.gen_query_conditions('attachedZoneUuids', 'in', \
                zone.uuid)
        bss = res_ops.safely_get_resource(res_ops.BACKUP_STORAGE, cond, \
                session_uuid, fields=['name'])
        for bs in bss:
            _set_backup_strorage_ref(zone_xml, bs.name)

        #query ps
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        pss = res_ops.safely_get_resource(res_ops.PRIMARY_STORAGE, cond, \
                session_uuid)

        if pss:
            pss_xml = etree.SubElement(zone_xml, "primaryStorages")
            _get_primary_storage(pss_xml, zone)

        #query cluster
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        clusters = res_ops.safely_get_resource(res_ops.CLUSTER, cond, \
                session_uuid)
        if clusters:
            clusters_xml = etree.SubElement(zone_xml, "clusters")
            _get_cluster(clusters_xml, clusters)

        #add l2
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        l2s = res_ops.safely_get_resource(res_ops.L2_NETWORK, cond, \
                session_uuid)
        if l2s:
            l2s_xml = etree.SubElement(zone_xml, "l2Networks")
            #query no vlan
            cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
            cond = res_ops.gen_query_conditions('type', '=', 'L2NoVlanNetwork')
            l2s_no_vlan = res_ops.safely_get_resource(res_ops.L2_NETWORK, 
                    cond, session_uuid)

            for l2 in l2s_no_vlan:
                l2_no_vlan_obj = JsonToXml(l2, 'l2NoVlanNetwork', l2s_xml, 
                        'type zoneUuid')
                l2_xml = l2_no_vlan_obj.generate_xml()
                _add_l3(l2_xml, l2)

            #query vlan
            cond = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
            l2s_vlan = res_ops.safely_get_resource(res_ops.L2_VLAN_NETWORK, 
                    cond, session_uuid)

            for l2 in l2s_vlan:
                l2_vlan_xml_obj = JsonToXml(l2, 'l2VlanNetwork', l2s_xml, 
                        'type zoneUuid')
                l2_xml = l2_vlan_xml_obj.generate_xml()
                _add_l3(l2_xml, l2)