12345678910111213141516171819202122232425 |
- def get_inventory(self):
- if len(self.resource_groups) > 0:
- # get VMs for requested resource groups
- for resource_group in self.resource_groups:
- try:
- virtual_machines = self._compute_client.virtual_machines.list(resource_group)
- except Exception as exc:
- sys.exit("Error: fetching virtual machines for resource group {0} - {1}".format(resource_group, str(exc)))
- if self._args.host or self.tags:
- selected_machines = self._selected_machines(virtual_machines)
- self._load_machines(selected_machines)
- else:
- self._load_machines(virtual_machines)
- else:
- # get all VMs within the subscription
- try:
- virtual_machines = self._compute_client.virtual_machines.list_all()
- except Exception as exc:
- sys.exit("Error: fetching virtual machines - {0}".format(str(exc)))
- if self._args.host or self.tags or self.locations:
- selected_machines = self._selected_machines(virtual_machines)
- self._load_machines(selected_machines)
- else:
- self._load_machines(virtual_machines)
|