Exemple #1
0
    def render(self, session, hostname, machine, cpuname, cpuvendor, cpuspeed,
               cpucount, memory, cluster, share, fullinfo, style, **arguments):
        if fullinfo or style != 'raw':
            q = search_hardware_entity_query(session, Machine, **arguments)
        else:
            q = search_hardware_entity_query(session, Machine.label, **arguments)
        if machine:
            q = q.filter_by(label=machine)
        if hostname:
            dns_rec = DnsRecord.get_unique(session, fqdn=hostname, compel=True)
            q = q.filter(Machine.primary_name_id == dns_rec.id)
        if cpuname or cpuvendor or cpuspeed is not None:
            subq = Cpu.get_matching_query(session, name=cpuname,
                                          vendor=cpuvendor, speed=cpuspeed,
                                          compel=True)
            q = q.filter(Machine.cpu_id.in_(subq))
        if cpucount is not None:
            q = q.filter_by(cpu_quantity=cpucount)
        if memory is not None:
            q = q.filter_by(memory=memory)
        if cluster:
            dbcluster = Cluster.get_unique(session, cluster, compel=True)
            if isinstance(dbcluster, MetaCluster):
                q = q.join('vm_container', ClusterResource, Cluster)
                q = q.filter_by(metacluster=dbcluster)
            else:
                q = q.join('vm_container', ClusterResource)
                q = q.filter_by(cluster=dbcluster)
            q = q.reset_joinpoint()
        if share:
            v2shares = session.query(Share.id).filter_by(name=share)
            if not v2shares.count():
                raise NotFoundException("No shares found with name {0}."
                                        .format(share))

            NasAlias = aliased(VirtualNasDisk)
            q = q.join('disks', (NasAlias, NasAlias.id == Disk.id))
            q = q.filter(NasAlias.share_id.in_(v2shares.subquery()))
            q = q.reset_joinpoint()

        if fullinfo or style != "raw":
            q = q.options(joinedload('location'),
                          subqueryload('interfaces'),
                          lazyload('interfaces.hardware_entity'),
                          joinedload('interfaces.assignments'),
                          joinedload('interfaces.assignments.dns_records'),
                          joinedload('chassis_slot'),
                          subqueryload('chassis_slot.chassis'),
                          subqueryload('disks'),
                          subqueryload('host'),
                          lazyload('host.hardware_entity'),
                          subqueryload('host.services_used'),
                          subqueryload('host._cluster'),
                          lazyload('host._cluster.host'))
            return q.all()
        return StringAttributeList(q.all(), "label")
Exemple #2
0
 def render(self, session, fullinfo, style, **arguments):
     if fullinfo or style != "raw":
         q = search_hardware_entity_query(session, HardwareEntity, **arguments)
         q = q.options(joinedload('location'),
                       subqueryload('interfaces'),
                       lazyload('interfaces.hardware_entity'),
                       joinedload('interfaces.assignments'),
                       joinedload('interfaces.assignments.dns_records'))
         return q.all()
     else:
         q = search_hardware_entity_query(session, HardwareEntity.label, **arguments)
         return StringAttributeList(q.all(), "label")
Exemple #3
0
    def render(self, session, hostname, machine, cpuname, cpuvendor, cpuspeed, 
               cpucount, memory, cluster, share, fullinfo, style, **arguments):
        if fullinfo or style != 'raw':
            q = search_hardware_entity_query(session, Machine, **arguments)
        else:
            q = search_hardware_entity_query(session, Machine.label, **arguments)
        if machine:
            q = q.filter_by(label=machine)
        if hostname:
            dns_rec = DnsRecord.get_unique(session, fqdn=hostname, compel=True)
            q = q.filter(Machine.primary_name_id==dns_rec.id)
        if cpuname or cpuvendor or cpuspeed is not None:
            subq = Cpu.get_matching_query(session, name=cpuname,
                                          vendor=cpuvendor, speed=cpuspeed,
                                          compel=True)
            q = q.filter(Machine.cpu_id.in_(subq))
        if cpucount is not None:
            q = q.filter_by(cpu_quantity=cpucount)
        if memory is not None:
            q = q.filter_by(memory=memory)
        if cluster:
            dbcluster = Cluster.get_unique(session, cluster, compel=True)
            if isinstance(dbcluster, MetaCluster):
                q = q.join('vm_container', ClusterResource, Cluster)
                q = q.filter_by(metacluster=dbcluster)
            else:
                q = q.join('vm_container', ClusterResource)
                q = q.filter_by(cluster=dbcluster)
            q = q.reset_joinpoint()
        if share:
            #v2
            v2shares = session.query(Share.id).filter_by(name=share).all()
            if v2shares:
                NasAlias = aliased(VirtualDisk)
                q = q.join('disks', (NasAlias, NasAlias.id == Disk.id))
                q = q.filter(
                    NasAlias.share_id.in_(map(lambda s: s[0], v2shares)))
                q = q.reset_joinpoint()

        if fullinfo:
            q = q.options(joinedload('location'),
                          subqueryload('interfaces'),
                          joinedload('interfaces.assignments'),
                          joinedload('interfaces.assignments.dns_records'),
                          joinedload('chassis_slot'),
                          subqueryload('chassis_slot.chassis'),
                          subqueryload('disks'),
                          subqueryload('host'),
                          subqueryload('host.services_used'),
                          subqueryload('host._cluster'))
            return q.all()
        return SimpleMachineList(q.all())
Exemple #4
0
    def render(self, session, fullinfo, style, **arguments):
        if fullinfo or style != "raw":
            q = search_hardware_entity_query(session, HardwareEntity,
                                             **arguments)
        else:
            q = search_hardware_entity_query(session, HardwareEntity.label,
                                             **arguments)

        if fullinfo:
            q = q.options(joinedload('location'), subqueryload('interfaces'),
                          joinedload('interfaces.assignments'),
                          joinedload('interfaces.assignments.dns_records'))
            return q.all()
        else:
            return SimpleHardwareEntityList(q.all())
Exemple #5
0
    def render(self, session, switch, type, vlan, fullinfo, **arguments):
        q = search_hardware_entity_query(session,
                                         hardware_type=Switch,
                                         **arguments)
        if type:
            q = q.filter_by(switch_type=type)
        if switch:
            dbswitch = Switch.get_unique(session, switch, compel=True)
            q = q.filter_by(id=dbswitch.id)

        if vlan:
            q = q.join("observed_vlans", "vlan").filter_by(vlan_id=vlan)
            q = q.reset_joinpoint()

        # Prefer the primary name for ordering
        q = q.outerjoin(DnsRecord, (Fqdn, DnsRecord.fqdn_id == Fqdn.id),
                        DnsDomain)
        q = q.options(contains_eager('primary_name'),
                      contains_eager('primary_name.fqdn'),
                      contains_eager('primary_name.fqdn.dns_domain'))
        q = q.reset_joinpoint()
        q = q.order_by(Fqdn.name, DnsDomain.name, Switch.label)

        if fullinfo:
            q = q.options(
                joinedload('location'),
                subqueryload('interfaces'),
                joinedload('interfaces.assignments'),
                joinedload('interfaces.assignments.dns_records'),
                joinedload('interfaces.assignments.network'),
                subqueryload('observed_macs'),
                undefer('observed_macs.creation_date'),
                subqueryload('observed_vlans'),
                undefer('observed_vlans.creation_date'),
                joinedload('observed_vlans.network'),
                subqueryload('model'),
                # Switches don't have machine specs, but the formatter
                # checks for their existence anyway
                joinedload('model.machine_specs'))
            return q.all()
        return SimpleSwitchList(q.all())
    def render(self, session, network_device, type, vlan, fullinfo, style,
               **arguments):
        q = search_hardware_entity_query(session, hardware_type=NetworkDevice,
                                         **arguments)
        if type:
            q = q.filter_by(switch_type=type)
        if network_device:
            dbnetdev = NetworkDevice.get_unique(session, network_device, compel=True)
            q = q.filter_by(id=dbnetdev.id)

        if vlan:
            q = q.join("observed_vlans", "vlan").filter_by(vlan_id=vlan)
            q = q.reset_joinpoint()

        # Prefer the primary name for ordering
        q = q.outerjoin(DnsRecord, (Fqdn, DnsRecord.fqdn_id == Fqdn.id),
                        DnsDomain)
        q = q.options(contains_eager('primary_name'),
                      contains_eager('primary_name.fqdn'),
                      contains_eager('primary_name.fqdn.dns_domain'))
        q = q.reset_joinpoint()
        q = q.order_by(Fqdn.name, DnsDomain.name, NetworkDevice.label)

        if fullinfo or style != 'raw':
            q = q.options(joinedload('location'),
                          subqueryload('interfaces'),
                          joinedload('interfaces.assignments'),
                          joinedload('interfaces.assignments.dns_records'),
                          joinedload('interfaces.assignments.network'),
                          subqueryload('observed_macs'),
                          undefer('observed_macs.creation_date'),
                          subqueryload('observed_vlans'),
                          undefer('observed_vlans.creation_date'),
                          joinedload('observed_vlans.network'),
                          subqueryload('model'),
                          # Switches don't have machine specs, but the formatter
                          # checks for their existence anyway
                          joinedload('model.machine_specs'))
            return q.all()
        return StringAttributeList(q.all(), "printable_name")