mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Revert "Backport #19566 to 2014.7"
This commit is contained in:
parent
eb19ccd99e
commit
9fef292d3d
@ -36,17 +36,19 @@ Example ``/etc/salt/cloud.providers`` or
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
import copy
|
||||
import logging
|
||||
import pprint
|
||||
import time
|
||||
import yaml
|
||||
|
||||
# Import salt libs
|
||||
import salt.config as config
|
||||
from salt.exceptions import SaltCloudSystemExit
|
||||
import salt.utils.cloud
|
||||
|
||||
|
||||
# Import python libs
|
||||
# Import salt cloud libs
|
||||
# Import azure libs
|
||||
HAS_LIBS = False
|
||||
try:
|
||||
@ -710,37 +712,6 @@ def create(vm_):
|
||||
)
|
||||
)
|
||||
|
||||
# Attaching volumes
|
||||
volumes = config.get_cloud_config_value(
|
||||
'volumes', vm_, __opts__, search_global=True
|
||||
)
|
||||
if volumes:
|
||||
salt.utils.cloud.fire_event(
|
||||
'event',
|
||||
'attaching volumes',
|
||||
'salt/cloud/{0}/attaching_volumes'.format(vm_['name']),
|
||||
{'volumes': volumes},
|
||||
transport=__opts__['transport']
|
||||
)
|
||||
|
||||
log.info('Create and attach volumes to node {0}'.format(vm_['name']))
|
||||
created = create_attach_volumes(
|
||||
vm_['name'],
|
||||
{
|
||||
'volumes': volumes,
|
||||
'service_name': service_name,
|
||||
'deployment_name': vm_['name'],
|
||||
'media_link': media_link,
|
||||
'role_name': vm_['name'],
|
||||
'del_all_vols_on_destroy': vm_.get('set_del_all_vols_on_destroy', False)
|
||||
},
|
||||
call='action'
|
||||
)
|
||||
ret['Attached Volumes'] = created
|
||||
|
||||
for key, value in salt.utils.cloud.bootstrap(vm_, __opts__).items():
|
||||
ret.setdefault(key, value)
|
||||
|
||||
data = show_instance(vm_['name'], call='action')
|
||||
log.info('Created Cloud VM {0[name]!r}'.format(vm_))
|
||||
log.debug(
|
||||
@ -766,97 +737,6 @@ def create(vm_):
|
||||
return ret
|
||||
|
||||
|
||||
def create_attach_volumes(name, kwargs, call=None, wait_to_finish=True):
|
||||
'''
|
||||
Create and attach volumes to created node
|
||||
'''
|
||||
if call != 'action':
|
||||
raise SaltCloudSystemExit(
|
||||
'The create_attach_volumes action must be called with '
|
||||
'-a or --action.'
|
||||
)
|
||||
|
||||
if isinstance(kwargs['volumes'], str):
|
||||
volumes = yaml.safe_load(kwargs['volumes'])
|
||||
else:
|
||||
volumes = kwargs['volumes']
|
||||
|
||||
# From the Azure .NET SDK doc
|
||||
#
|
||||
# The Create Data Disk operation adds a data disk to a virtual
|
||||
# machine. There are three ways to create the data disk using the
|
||||
# Add Data Disk operation.
|
||||
# Option 1 - Attach an empty data disk to
|
||||
# the role by specifying the disk label and location of the disk
|
||||
# image. Do not include the DiskName and SourceMediaLink elements in
|
||||
# the request body. Include the MediaLink element and reference a
|
||||
# blob that is in the same geographical region as the role. You can
|
||||
# also omit the MediaLink element. In this usage, Azure will create
|
||||
# the data disk in the storage account configured as default for the
|
||||
# role.
|
||||
# Option 2 - Attach an existing data disk that is in the image
|
||||
# repository. Do not include the DiskName and SourceMediaLink
|
||||
# elements in the request body. Specify the data disk to use by
|
||||
# including the DiskName element. Note: If included the in the
|
||||
# response body, the MediaLink and LogicalDiskSizeInGB elements are
|
||||
# ignored.
|
||||
# Option 3 - Specify the location of a blob in your storage
|
||||
# account that contain a disk image to use. Include the
|
||||
# SourceMediaLink element. Note: If the MediaLink element
|
||||
# isincluded, it is ignored. (see
|
||||
# http://msdn.microsoft.com/en-us/library/windowsazure/jj157199.aspx
|
||||
# for more information)
|
||||
#
|
||||
# Here only option 1 is implemented
|
||||
conn = get_conn()
|
||||
ret = []
|
||||
for volume in volumes:
|
||||
if "disk_name" in volume:
|
||||
log.error("You cannot specify a disk_name. Only new volumes are allowed")
|
||||
return False
|
||||
# Use the size keyword to set a size, but you can use the
|
||||
# azure name too. If neither is set, the disk has size 100GB
|
||||
volume.setdefault("logical_disk_size_in_gb", volume.get("size", 100))
|
||||
volume.setdefault("host_caching", "ReadOnly")
|
||||
volume.setdefault("lun", 0)
|
||||
# The media link is vm_name-disk-[0-15].vhd
|
||||
volume.setdefault("media_link",
|
||||
kwargs["media_link"][:-4] + "-disk-{0}.vhd".format(volume["lun"]))
|
||||
volume.setdefault("disk_label",
|
||||
kwargs["role_name"] + "-disk-{0}".format(volume["lun"]))
|
||||
volume_dict = {
|
||||
'volume_name': volume["lun"],
|
||||
'disk_label': volume["disk_label"]
|
||||
}
|
||||
|
||||
# Preparing the volume dict to be passed with **
|
||||
kwargs_add_data_disk = ["lun", "host_caching", "media_link",
|
||||
"disk_label", "disk_name",
|
||||
"logical_disk_size_in_gb",
|
||||
"source_media_link"]
|
||||
for key in set(volume.keys()) - set(kwargs_add_data_disk):
|
||||
del volume[key]
|
||||
|
||||
attach = conn.add_data_disk(kwargs["service_name"], kwargs["deployment_name"], kwargs["role_name"],
|
||||
**volume)
|
||||
log.debug(attach)
|
||||
|
||||
# If attach is None then everything is fine
|
||||
if attach:
|
||||
msg = (
|
||||
'{0} attached to {1} (aka {2})'.format(
|
||||
volume_dict['volume_name'],
|
||||
kwargs['role_name'],
|
||||
name,
|
||||
)
|
||||
)
|
||||
log.info(msg)
|
||||
ret.append(msg)
|
||||
else:
|
||||
log.error('Error attaching {0} on Azure'.format(volume_dict))
|
||||
return ret
|
||||
|
||||
|
||||
def destroy(name, conn=None, call=None, kwargs=None):
|
||||
'''
|
||||
Destroy a VM
|
||||
|
Loading…
Reference in New Issue
Block a user