Fixes azure_rm_snapshot (#64542) (#64547)

* feature enhancement: make a snapshot from an existing managed disk.

* remove default creation option in argu_spec of azure_rm_snapshot

* fix pep8 related issue

* fixing broken integration test
pull/64693/head
haiyuan_zhang 5 years ago committed by Zim Kalinowski
parent ca42cb2868
commit c11d73575b

@ -19,6 +19,8 @@ class AzureRMModuleBaseExt(AzureRMModuleBase):
# first check if option was passed
param = body.get(name)
if not param:
if spec[name].get('purgeIfNone', False):
body.pop(name, None)
continue
# check if pattern needs to be used
pattern = spec[name].get('pattern', None)

@ -17,7 +17,7 @@ DOCUMENTATION = '''
---
module: azure_rm_snapshot
version_added: '2.9'
short_description: Manage Azure Snapshot instance
short_description: Manage Azure Snapshot instance.
description:
- Create, update and delete instance of Azure Snapshot.
options:
@ -68,13 +68,17 @@ options:
description:
- This enumerates the possible sources of a disk's creation.
type: str
default: Import
choices:
- Import
- Copy
source_uri:
description:
- If I(createOption=Import), this is the URI of a blob to be imported into a managed disk.
type: str
source_id:
description:
- If I(createOption=Copy), this is the resource ID of a managed disk to be copied from.
type: str
state:
description:
- Assert the state of the Snapshot.
@ -82,8 +86,8 @@ options:
default: present
type: str
choices:
- absent
- present
- absent
- present
extends_documentation_fragment:
- azure
- azure_tags
@ -101,6 +105,15 @@ EXAMPLES = '''
creation_data:
create_option: Import
source_uri: 'https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd'
- name: Create a snapshot by copying an existing managed disk.
azure_rm_snapshot:
resource_group: myResourceGroup
name: mySnapshot
location: eastus
creation_data:
create_option: Copy
source_id: '/subscriptions/sub123/resourceGroups/group123/providers/Microsoft.Compute/disks/disk123'
'''
RETURN = '''
@ -114,10 +127,8 @@ id:
import time
import json
import re
from ansible.module_utils.azure_rm_common_ext import AzureRMModuleBaseExt
from ansible.module_utils.azure_rm_common_rest import GenericRestClient
from copy import deepcopy
try:
from msrestazure.azure_exceptions import CloudError
except ImportError:
@ -177,12 +188,17 @@ class AzureRMSnapshots(AzureRMModuleBaseExt):
create_option=dict(
type='str',
disposition='createOption',
choices=['Import'],
default='Import'
choices=['Import', 'Copy'],
),
source_uri=dict(
type='str',
disposition='sourceUri'
disposition='sourceUri',
purgeIfNone=True
),
source_id=dict(
type='str',
disposition='sourceResourceId',
purgeIfNone=True
)
)
),
@ -355,6 +371,7 @@ class AzureRMSnapshots(AzureRMModuleBaseExt):
expected_status_codes=self.status_code,
polling_timeout=600,
polling_interval=30)
response = json.loads(response.text)
found = True
self.log("Response : {0}".format(response))
# self.log("Snapshot instance : {0} found".format(response.name))

@ -53,7 +53,7 @@
- name: Create a snapshot by importing an unmanaged blob from the same subscription.
azure_rm_snapshot:
resource_group: "{{ resource_group }}"
name: mySnapshot
name: "mySnapshot-{{ rpfx }}"
location: eastus
creation_data:
create_option: Import

Loading…
Cancel
Save