azure_rm_15.py 5.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. def _load_machines(self, machines):
  2. for machine in machines:
  3. id_dict = azure_id_to_dict(machine.id)
  4. # TODO - The API is returning an ID value containing resource group name in ALL CAPS. If/when it gets
  5. # fixed, we should remove the .lower(). Opened Issue
  6. # #574: https://github.com/Azure/azure-sdk-for-python/issues/574
  7. resource_group = id_dict['resourceGroups'].lower()
  8. if self.group_by_security_group:
  9. self._get_security_groups(resource_group)
  10. host_vars = dict(
  11. ansible_host=None,
  12. private_ip=None,
  13. private_ip_alloc_method=None,
  14. public_ip=None,
  15. public_ip_name=None,
  16. public_ip_id=None,
  17. public_ip_alloc_method=None,
  18. fqdn=None,
  19. location=machine.location,
  20. name=machine.name,
  21. type=machine.type,
  22. id=machine.id,
  23. tags=machine.tags,
  24. network_interface_id=None,
  25. network_interface=None,
  26. resource_group=resource_group,
  27. mac_address=None,
  28. plan=(machine.plan.name if machine.plan else None),
  29. virtual_machine_size=machine.hardware_profile.vm_size,
  30. computer_name=(machine.os_profile.computer_name if machine.os_profile else None),
  31. provisioning_state=machine.provisioning_state,
  32. )
  33. host_vars['os_disk'] = dict(
  34. name=machine.storage_profile.os_disk.name,
  35. operating_system_type=machine.storage_profile.os_disk.os_type.value
  36. )
  37. if self.include_powerstate:
  38. host_vars['powerstate'] = self._get_powerstate(resource_group, machine.name)
  39. if machine.storage_profile.image_reference:
  40. host_vars['image'] = dict(
  41. offer=machine.storage_profile.image_reference.offer,
  42. publisher=machine.storage_profile.image_reference.publisher,
  43. sku=machine.storage_profile.image_reference.sku,
  44. version=machine.storage_profile.image_reference.version
  45. )
  46. # Add windows details
  47. if machine.os_profile is not None and machine.os_profile.windows_configuration is not None:
  48. host_vars['windows_auto_updates_enabled'] = \
  49. machine.os_profile.windows_configuration.enable_automatic_updates
  50. host_vars['windows_timezone'] = machine.os_profile.windows_configuration.time_zone
  51. host_vars['windows_rm'] = None
  52. if machine.os_profile.windows_configuration.win_rm is not None:
  53. host_vars['windows_rm'] = dict(listeners=None)
  54. if machine.os_profile.windows_configuration.win_rm.listeners is not None:
  55. host_vars['windows_rm']['listeners'] = []
  56. for listener in machine.os_profile.windows_configuration.win_rm.listeners:
  57. host_vars['windows_rm']['listeners'].append(dict(protocol=listener.protocol,
  58. certificate_url=listener.certificate_url))
  59. for interface in machine.network_profile.network_interfaces:
  60. interface_reference = self._parse_ref_id(interface.id)
  61. network_interface = self._network_client.network_interfaces.get(
  62. interface_reference['resourceGroups'],
  63. interface_reference['networkInterfaces'])
  64. if network_interface.primary:
  65. if self.group_by_security_group and \
  66. self._security_groups[resource_group].get(network_interface.id, None):
  67. host_vars['security_group'] = \
  68. self._security_groups[resource_group][network_interface.id]['name']
  69. host_vars['security_group_id'] = \
  70. self._security_groups[resource_group][network_interface.id]['id']
  71. host_vars['network_interface'] = network_interface.name
  72. host_vars['network_interface_id'] = network_interface.id
  73. host_vars['mac_address'] = network_interface.mac_address
  74. for ip_config in network_interface.ip_configurations:
  75. host_vars['private_ip'] = ip_config.private_ip_address
  76. host_vars['private_ip_alloc_method'] = ip_config.private_ip_allocation_method
  77. if ip_config.public_ip_address:
  78. public_ip_reference = self._parse_ref_id(ip_config.public_ip_address.id)
  79. public_ip_address = self._network_client.public_ip_addresses.get(
  80. public_ip_reference['resourceGroups'],
  81. public_ip_reference['publicIPAddresses'])
  82. host_vars['ansible_host'] = public_ip_address.ip_address
  83. host_vars['public_ip'] = public_ip_address.ip_address
  84. host_vars['public_ip_name'] = public_ip_address.name
  85. host_vars['public_ip_alloc_method'] = public_ip_address.public_ip_allocation_method
  86. host_vars['public_ip_id'] = public_ip_address.id
  87. if public_ip_address.dns_settings:
  88. host_vars['fqdn'] = public_ip_address.dns_settings.fqdn
  89. self._add_host(host_vars)