Example #1
0
    def get_host(self, hostname):
        '''
        Read info about a specific host or VM from cache or VMware API.
        '''
        inv = self._get_cache(hostname, None)
        if inv is not None:
            return inv

        if not self.guests_only:
            try:
                host = HostSystem.get(self.client, name=hostname)
                inv = self._get_host_info(host)
            except ObjectNotFoundError:
                pass

        if inv is None:
            try:
                vm = VirtualMachine.get(self.client, name=hostname)
                inv = self._get_vm_info(vm)
            except ObjectNotFoundError:
                pass

        if inv is not None:
            self._put_cache(hostname, inv)
        return inv or {}
Example #2
0
    def get_host(self, hostname):
        '''
        Read info about a specific host or VM from cache or VMware API.
        '''
        inv = self._get_cache(hostname, None)
        if inv is not None:
            return inv

        if not self.guests_only:
            try:
                host = HostSystem.get(self.client, name=hostname)
                inv = self._get_host_info(host)
            except ObjectNotFoundError:
                pass

        if inv is None:
            try:
                vm = VirtualMachine.get(self.client, name=hostname)
                inv = self._get_vm_info(vm)
            except ObjectNotFoundError:
                pass

        if inv is not None:
            self._put_cache(hostname, inv)
        return inv or {}
Example #3
0
 def get_host_by_name(self, hostname):
     try:
         print 'hostname: ',
         print hostname
         return HostSystem.get(self.client, name=hostname)
     except ObjectNotFoundError as ex:
         traceback.print_stack()
         raise ObjectNotFoundError('Could not find HostSystem:%s. %s' % (hostname, to_str(ex)))
Example #4
0
    def get_hs(self):
        if self._hs is None:
            try:
                self._hs = HostSystem.get(self.client, name=self.hostname)

            except ObjectNotFoundError as ex:
                traceback.print_stack()
                raise ObjectNotFoundError('Could not find HostSystem:%s. %s' % (self.hostname, to_str(ex)))

        if self._hs is None:
            raise Exception('ESXiNode Could not get host systemi %s from vCenter!' % self.hostname)
        return self._hs
Example #5
0
def main(options):
    client = Client(server=options.server, username=options.username,
                    password=options.password)

    print('Successfully connected to %s' % client.server)

    # Get a HostSystem object representing the host
    host = HostSystem.get(client, name=options.hostsystem)

    # Preload the name attribute of all items in the vm attribute. Read the
    # manual as this significantly speeds up queries for ManagedObject's
    host.preload("vm", properties=["name"])

    # Iterate over the items in host.vm and print their names
    for vm in sorted(host.vm):
        print(vm.name)

    # Close the connection
    client.logout()
Example #6
0
def main(options):
    client = Client(server=options.server,
                    username=options.username,
                    password=options.password)

    print('Successfully connected to %s' % client.server)

    # Get a HostSystem object representing the host
    host = HostSystem.get(client, name=options.hostsystem)

    # Preload the name attribute of all items in the vm attribute. Read the
    # manual as this significantly speeds up queries for ManagedObject's
    host.preload("vm", properties=["name"])

    # Iterate over the items in host.vm and print their names
    for vm in sorted(host.vm):
        print(vm.name)

    # Close the connection
    client.logout()
 def initialize_hosts(self):
     for h in self.hosts:
         fd = self.create_log(h)
         host_ins = HostSystem.get(self.client, name=h)
         host_obj = Host_info(host_ins)
         self.hostsconn_fds.append((fd, host_obj))
Example #8
0
 def initialize_hosts(self):
     for h in self.hosts:
         fd = self.create_log(h)
         host_ins = HostSystem.get(self.client, name=h)
         host_obj = Host_info(host_ins)
         self.hostsconn_fds.append((fd, host_obj))