Ejemplo n.º 1
0
 def all_vms(self):
     property_spec = vmodl.query.PropertyCollector.PropertySpec()
     property_spec.all = False
     property_spec.pathSet = ['name', 'config.template']
     property_spec.type = 'VirtualMachine'
     pfs = self._build_filter_spec(self.content.rootFolder, property_spec)
     object_contents = self.content.propertyCollector.RetrieveProperties(specSet=[pfs])
     result = []
     for vm in object_contents:
         vm_props = {p.name: p.val for p in vm.propSet}
         if vm_props.get('config.template'):
             continue
         try:
             ip = str(vm.obj.summary.guest.ipAddress)
         except AttributeError:
             ip = None
         try:
             uuid = str(vm.obj.summary.config.uuid)
         except AttributeError:
             uuid = None
         result.append(
             VMInfo(
                 uuid,
                 str(vm.obj.summary.config.name),
                 str(vm.obj.summary.runtime.powerState),
                 ip,
             )
         )
     return result
Ejemplo n.º 2
0
    def all_vms(self, **kwargs):
        vm_list = []
        data = self.run_script("""
            $outputCollection = @()
            $VMs = Get-SCVirtualMachine -All -VMMServer $scvmm_server |
            Select VMId, Name, StatusString
            $NetAdapter = Get-SCVirtualNetworkAdapter -VMMServer $scvmm_server -All |
            Select ID, Name, IPv4Addresses
            #Associate objects
            $VMs | ForEach-Object{
                $vm_object = $_
                $ip_object = $NetAdapter | Where-Object {$_.Name -eq $vm_object.Name}

                #Make a combined object
                $outObj = "" | Select VMId, Name, Status, IPv4
                $outObj.VMId = if($vm_object.VMId){$vm_object.VMId} else {"None"}
                $outObj.Name = $vm_object.Name
                $outObj.Status = $vm_object.StatusString
                $outObj.IPv4 = if($ip_object.IPv4Addresses){$ip_object.IPv4Addresses} else {"None"}
                #Add the object to the collection

                $outputCollection += $outObj
            }
            $outputCollection | ConvertTo-Xml -as String
            """)
        vms = etree.fromstring(data)
        for vm in vms:
            VMId = vm.xpath("./Property[@Name='VMId']/text()")[0],
            Name = vm.xpath("./Property[@Name='Name']/text()")[0],
            Status = vm.xpath("./Property[@Name='Status']/text()")[0],
            IPv4 = vm.xpath("./Property[@Name='IPv4']/text()")[0]
            vm_data = (None if VMId == 'None' else VMId[0], Name[0], Status[0],
                       None if IPv4 == 'None' else IPv4)
            vm_list.append(VMInfo(*vm_data))
        return vm_list
Ejemplo n.º 3
0
    def all_vms(self, by_zone=False):
        """List all VMs in the GCE account, unfiltered by default

        Args:
            by_zone: boolean, True to filter by the current object's zone

        Returns:
            List of VMInfo nametuples
        """
        result = []
        zones = self._compute.zones().list(project=self._project).execute()
        for zone in zones.get('items', []):
            zone_name = zone.get('name', None)
            if by_zone and zone_name != self._zone:
                continue
            for vm in self._get_zone_instances(zone_name).get('items', []):
                if vm['id'] and vm['name'] and vm['status'] and vm.get(
                        'networkInterfaces'):

                    result.append(
                        VMInfo(
                            vm['id'],
                            vm['name'],
                            vm['status'],
                            vm.get('networkInterfaces')[0].get('networkIP'),
                        ))
        else:
            self.logger.info(
                'No matching zone found in all_vms with by_zone=True')
        return result
Ejemplo n.º 4
0
 def all_vms(self):
     result = []
     for vm in self._get_all_instances():
         ip = None
         for network_nics in vm._info["addresses"].itervalues():
             for nic in network_nics:
                 if nic['OS-EXT-IPS:type'] == 'floating':
                     ip = str(nic['addr'])
         result.append(VMInfo(
             vm.id,
             vm.name,
             vm.status,
             ip,
         ))
     return result
Ejemplo n.º 5
0
 def all_vms(self):
     result = []
     for vm in self.api.vms.list():
         try:
             ip = vm.get_guest_info().get_ips().get_ip()[0].get_address()
         except (AttributeError, IndexError):
             ip = None
         result.append(
             VMInfo(
                 vm.get_id(),
                 vm.get_name(),
                 vm.get_status().get_state(),
                 ip,
             ))
     return result
Ejemplo n.º 6
0
    def all_vms(self):
        result = []
        zones = self._compute.zones().list(project=self._project).execute()
        for zone in zones.get('items', []):
            zone_name = zone.get('name', None)
            for vm in self._get_zone_instances(zone_name).get('items', []):
                if vm['id'] and vm['name'] and vm['status'] and vm.get(
                        'networkInterfaces'):

                    result.append(
                        VMInfo(
                            vm['id'],
                            vm['name'],
                            vm['status'],
                            vm.get('networkInterfaces')[0].get('networkIP'),
                        ))
        return result