Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add plan support to azure_rm_virtualmachine #32401

Merged
merged 1 commit into from
Nov 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 34 additions & 2 deletions lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@
- "It can be 'all' or a list with any of the following: ['network_interfaces', 'virtual_storage', 'public_ips']"
- Any other input will be ignored
default: ['all']
plan:
description:
- A dictionary describing a third-party billing plan for an instance
version_added: 2.5
suboptions:
name:
description:
- billing plan name
required: true
product:
description:
- product name
required: true
publisher:
description:
- publisher offering the plan
required: true
promotion_code:
description:
- optional promotion code

extends_documentation_fragment:
- azure
Expand Down Expand Up @@ -544,7 +564,7 @@
VirtualHardDisk, ManagedDiskParameters, \
ImageReference, NetworkProfile, LinuxConfiguration, \
SshConfiguration, SshPublicKey, VirtualMachineSizeTypes, \
DiskCreateOptionTypes
DiskCreateOptionTypes, Plan
from azure.mgmt.network.models import PublicIPAddress, NetworkSecurityGroup, NetworkInterface, \
NetworkInterfaceIPConfiguration, Subnet
from azure.mgmt.storage.models import StorageAccountCreateParameters, Sku
Expand Down Expand Up @@ -606,6 +626,7 @@ def __init__(self):
restarted=dict(type='bool', default=False),
started=dict(type='bool', default=True),
data_disks=dict(type='list'),
plan=dict(type='dict')
)

self.resource_group = None
Expand Down Expand Up @@ -639,6 +660,7 @@ def __init__(self):
self.started = None
self.differences = None
self.data_disks = None
self.plan = None

self.results = dict(
changed=False,
Expand Down Expand Up @@ -698,12 +720,16 @@ def exec_module(self, **kwargs):
if self.image:
if not self.image.get('publisher') or not self.image.get('offer') or not self.image.get('sku') \
or not self.image.get('version'):
self.error("parameter error: expecting image to contain publisher, offer, sku and version keys.")
self.fail("parameter error: expecting image to contain publisher, offer, sku and version keys.")
image_version = self.get_image_version()
if self.image['version'] == 'latest':
self.image['version'] = image_version.name
self.log("Using image version {0}".format(self.image['version']))

if self.plan:
if not self.plan.get('name') or not self.plan.get('product') or not self.plan.get('publisher'):
self.fail("parameter error: plan must include name, product, and publisher")

if not self.storage_blob_name and not self.managed_disk_type:
self.storage_blob_name = self.name + '.vhd'
elif self.managed_disk_type:
Expand Down Expand Up @@ -850,6 +876,11 @@ def exec_module(self, **kwargs):
vhd = None
managed_disk = ManagedDiskParameters(storage_account_type=self.managed_disk_type)

plan = None
if self.plan:
plan = Plan(name=self.plan.get('name'), product=self.plan.get('product'), publisher=self.plan.get('publisher'),
promotion_code=self.product.get('promotion_code'))

vm_resource = VirtualMachine(
self.location,
tags=self.tags,
Expand Down Expand Up @@ -878,6 +909,7 @@ def exec_module(self, **kwargs):
network_profile=NetworkProfile(
network_interfaces=nics
),
plan=plan
)

if self.admin_password:
Expand Down