azure_rm_14.py 1.3 KB

12345678910111213141516171819202122232425
  1. def get_inventory(self):
  2. if len(self.resource_groups) > 0:
  3. # get VMs for requested resource groups
  4. for resource_group in self.resource_groups:
  5. try:
  6. virtual_machines = self._compute_client.virtual_machines.list(resource_group)
  7. except Exception as exc:
  8. sys.exit("Error: fetching virtual machines for resource group {0} - {1}".format(resource_group, str(exc)))
  9. if self._args.host or self.tags:
  10. selected_machines = self._selected_machines(virtual_machines)
  11. self._load_machines(selected_machines)
  12. else:
  13. self._load_machines(virtual_machines)
  14. else:
  15. # get all VMs within the subscription
  16. try:
  17. virtual_machines = self._compute_client.virtual_machines.list_all()
  18. except Exception as exc:
  19. sys.exit("Error: fetching virtual machines - {0}".format(str(exc)))
  20. if self._args.host or self.tags or self.locations:
  21. selected_machines = self._selected_machines(virtual_machines)
  22. self._load_machines(selected_machines)
  23. else:
  24. self._load_machines(virtual_machines)