| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
|
| 12 |
DOCUMENTATION = ''' |
| 13 |
--- |
| 14 |
module: azure_rm_virtualmachinesize_info |
| 15 |
|
| 16 |
version_added: "1.8.0" |
| 17 |
|
| 18 |
short_description: Get facts for virtual machine sizes |
| 19 |
|
| 20 |
description: |
| 21 |
- Get available virtual machine size profiles for a location |
| 22 |
|
| 23 |
options: |
| 24 |
location: |
| 25 |
description: |
| 26 |
- Location for which to list the available virtual machine size profiles |
| 27 |
required: true |
| 28 |
type: str |
| 29 |
name: |
| 30 |
description: |
| 31 |
- Name of a size to get information about |
| 32 |
type: str |
| 33 |
|
| 34 |
extends_documentation_fragment: |
| 35 |
- azure.azcollection.azure |
| 36 |
|
| 37 |
author: |
| 38 |
- Maxence Ardouin (@nbr23) |
| 39 |
|
| 40 |
''' |
| 41 |
|
| 42 |
EXAMPLES = ''' |
| 43 |
- name: Get all virtual machine size info in eastus |
| 44 |
azure_rm_virtualmachinesize_info: |
| 45 |
location: eastus |
| 46 |
|
| 47 |
- name: Get virtual machine size info for eastus for Standard_A1_v2 |
| 48 |
azure_rm_virtualmachinesize_info: |
| 49 |
location: eastus |
| 50 |
name: Standard_A1_v2 |
| 51 |
''' |
| 52 |
|
| 53 |
RETURN = ''' |
| 54 |
sizes: |
| 55 |
description: |
| 56 |
- List of virtual machine size profiles available for the location. |
| 57 |
returned: always |
| 58 |
type: complex |
| 59 |
contains: |
| 60 |
name: |
| 61 |
description: |
| 62 |
- The name of the virtual machine size |
| 63 |
type: str |
| 64 |
sample: Standard_A1_v2 |
| 65 |
memoryInMB: |
| 66 |
description: |
| 67 |
- The amount of memory, in MB, supported by the virtual machine size |
| 68 |
type: int |
| 69 |
sample: 2048 |
| 70 |
numberOfCores: |
| 71 |
description: |
| 72 |
- The number of cores supported by the virtual machine size |
| 73 |
type: int |
| 74 |
sample: 1 |
| 75 |
maxDataDiskCount: |
| 76 |
description: |
| 77 |
- The maximum number of data disks that can be attached to the virtual machine size |
| 78 |
type: int |
| 79 |
sample: 2 |
| 80 |
osDiskSizeInMB: |
| 81 |
description: |
| 82 |
- The OS disk size, in MB, allowed by the virtual machine size |
| 83 |
type: int |
| 84 |
sample: 1047552 |
| 85 |
resourceDiskSizeInMB: |
| 86 |
description: |
| 87 |
- The resource disk size, in MB, allowed by the virtual machine size |
| 88 |
type: int |
| 89 |
sample: 10240 |
| 90 |
''' |
| 91 |
|
| 92 |
try: |
| 93 |
from azure.core.exceptions import ResourceNotFoundError |
| 94 |
except Exception: |
| 95 |
|
| 96 |
pass |
| 97 |
|
| 98 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 99 |
|
| 100 |
AZURE_OBJECT_CLASS = 'VirtualMachineSize' |
| 101 |
|
| 102 |
AZURE_ENUM_MODULES = ['azure.mgmt.compute.models'] |
| 103 |
|
| 104 |
|
| 105 |
class AzureRMVirtualMachineSizeInfo(AzureRMModuleBase): |
| 106 |
|
| 107 |
def __init__(self): |
| 108 |
|
| 109 |
self.module_arg_spec = dict( |
| 110 |
location=dict(type='str', required=True), |
| 111 |
name=dict(type='str') |
| 112 |
) |
| 113 |
|
| 114 |
self.results = dict( |
| 115 |
changed=False, |
| 116 |
sizes=[] |
| 117 |
) |
| 118 |
|
| 119 |
self.location = None |
| 120 |
self.name = None |
| 121 |
|
| 122 |
super(AzureRMVirtualMachineSizeInfo, self).__init__(self.module_arg_spec, |
| 123 |
supports_check_mode=True, |
| 124 |
supports_tags=False, |
| 125 |
facts_module=True) |
| 126 |
|
| 127 |
def exec_module(self, **kwargs): |
| 128 |
for key in self.module_arg_spec: |
| 129 |
setattr(self, key, kwargs[key]) |
| 130 |
|
| 131 |
self.results['sizes'] = self.list_items_by_location() |
| 132 |
return self.results |
| 133 |
|
| 134 |
def list_items_by_location(self): |
| 135 |
self.log('List items by location') |
| 136 |
try: |
| 137 |
items = self.compute_client.virtual_machine_sizes.list(location=self.location) |
| 138 |
except ResourceNotFoundError as exc: |
| 139 |
self.fail("Failed to list items - {0}".format(str(exc))) |
| 140 |
return [self.serialize_size(item) for item in items if self.name is None or self.name == item.name] |
| 141 |
|
| 142 |
def serialize_size(self, size): |
| 143 |
''' |
| 144 |
Convert a VirtualMachineSize object to dict. |
| 145 |
|
| 146 |
:param size: VirtualMachineSize object |
| 147 |
:return: dict |
| 148 |
''' |
| 149 |
|
| 150 |
return self.serialize_obj(size, AZURE_OBJECT_CLASS, enum_modules=AZURE_ENUM_MODULES) |
| 151 |
|
| 152 |
|
| 153 |
def main(): |
| 154 |
AzureRMVirtualMachineSizeInfo() |
| 155 |
|
| 156 |
|
| 157 |
if __name__ == '__main__': |
| 158 |
main() |