Merge pull request #9259 from techhat/ec2

Allow avail* functions to be called with -f in salt-cloud
This commit is contained in:
Joseph Hall 2013-12-13 19:56:28 -08:00
commit 2b3897d114
8 changed files with 162 additions and 25 deletions

View File

@ -83,11 +83,17 @@ def get_configured_provider():
)
def avail_locations():
def avail_locations(call=None):
'''
Return a dict of all available VM locations on the cloud provider with
relevant data
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_locations function must be called with '
'-f or --function, or with the --list-locations option'
)
items = query(method='regions')
ret = {}
for region in items['regions']:
@ -98,10 +104,16 @@ def avail_locations():
return ret
def avail_images():
def avail_images(call=None):
'''
Return a list of the images that are on the provider
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_images function must be called with '
'-f or --function, or with the --list-images option'
)
items = query(method='images')
ret = {}
for image in items['images']:
@ -112,10 +124,16 @@ def avail_images():
return ret
def avail_sizes():
def avail_sizes(call=None):
'''
Return a list of the image sizes that are on the provider
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_sizes function must be called with '
'-f or --function, or with the --list-sizes option'
)
items = query(method='sizes')
ret = {}
for size in items['sizes']:

View File

@ -389,13 +389,19 @@ def _wait_for_spot_instance(update_callback,
timeout -= interval
def avail_sizes():
def avail_sizes(call=None):
'''
Return a dict of all available VM sizes on the cloud provider with
relevant data. Latest version can be found at:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_sizes function must be called with '
'-f or --function, or with the --list-sizes option'
)
sizes = {
'Cluster Compute': {
'cc2.8xlarge': {
@ -534,6 +540,12 @@ def avail_images(kwargs=None, call=None):
'''
Return a dict of all available VM images on the cloud provider.
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_images function must be called with '
'-f or --function, or with the --list-images option'
)
if type(kwargs) is not dict:
kwargs = {}
@ -669,10 +681,16 @@ def get_location(vm_=None):
)
def avail_locations():
def avail_locations(call=None):
'''
List all available locations
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_locations function must be called with '
'-f or --function, or with the --list-locations option'
)
ret = {}
params = {'Action': 'DescribeRegions'}

View File

@ -624,10 +624,16 @@ def get_location(vm_=None):
)
def avail_locations():
def avail_locations(call=None):
'''
List all available locations
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_locations function must be called with '
'-f or --function, or with the --list-locations option'
)
ret = {}
for key in JOYENT_LOCATIONS:
ret[key] = {
@ -814,7 +820,7 @@ def list_nodes_full(call=None):
return list_nodes(full=True)
def avail_images():
def avail_images(call=None):
'''
get list of available images
@ -824,6 +830,12 @@ def avail_images():
salt-cloud --list-images
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_images function must be called with '
'-f or --function, or with the --list-images option'
)
img_url = 'https://images.joyent.com/images'
request = urllib2.Request(img_url)
request.get_method = lambda: 'GET'
@ -844,7 +856,7 @@ def avail_images():
#return key_list(items=items)
def avail_sizes():
def avail_sizes(call=None):
'''
get list of available packages
@ -854,6 +866,12 @@ def avail_sizes():
salt-cloud --list-sizes
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_sizes function must be called with '
'-f or --function, or with the --list-sizes option'
)
rcode, items = query2(command='/my/packages')
if rcode not in VALID_RESPONSE_CODES:
return {}

View File

@ -111,10 +111,16 @@ def script(vm_):
)
def avail_locations(conn=None, call=None): # pylint disable=W0613
def avail_locations(conn=None, call=None):
'''
List available locations for Azure
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_locations function must be called with '
'-f or --function, or with the --list-locations option'
)
if not conn:
conn = get_conn()
@ -129,10 +135,16 @@ def avail_locations(conn=None, call=None): # pylint disable=W0613
return ret
def avail_images(conn=None, call=None): # pylint disable=W0613
def avail_images(conn=None, call=None):
'''
List available images for Azure
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_images function must be called with '
'-f or --function, or with the --list-images option'
)
if not conn:
conn = get_conn()
@ -157,11 +169,17 @@ def avail_images(conn=None, call=None): # pylint disable=W0613
return ret
def avail_sizes():
def avail_sizes(call=None):
'''
Because sizes are built into images with Azure, there will be no sizes to
return here
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_sizes function must be called with '
'-f or --function, or with the --list-sizes option'
)
return {
'ExtraSmall': {
'name': 'ExtraSmall',
@ -251,10 +269,16 @@ def list_nodes_full(conn=None, call=None):
return ret
def list_hosted_services(conn=None, call=None): # pylint disable=W0613
def list_hosted_services(conn=None, call=None):
'''
List VMs on this Azure account, with full information
'''
if call == 'action':
raise SaltCloudSystemExit(
'The list_hosted_services function must be called with '
'-f or --function'
)
if not conn:
conn = get_conn()
@ -670,7 +694,7 @@ def destroy(name, conn=None, call=None):
return ret
def list_storage_services(conn=None, call=None): # pylint disable=W0613
def list_storage_services(conn=None, call=None):
'''
List VMs on this Azure account, with full information
'''
@ -697,7 +721,7 @@ def list_storage_services(conn=None, call=None): # pylint disable=W0613
return ret
def list_disks(conn=None, call=None): # pylint disable=W0613
def list_disks(conn=None, call=None):
'''
Destroy a VM
'''

View File

@ -86,10 +86,16 @@ def get_configured_provider():
)
def avail_images():
def avail_images(call=None):
'''
Return a list of the images that are on the provider
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_images function must be called with '
'-f or --function, or with the --list-images option'
)
items = query(action='template')
ret = {}
for item in items:

View File

@ -99,10 +99,16 @@ def get_conn(service='SoftLayer_Hardware'):
return client[service]
def avail_locations():
def avail_locations(call=None):
'''
List all available locations
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_locations function must be called with '
'-f or --function, or with the --list-locations option'
)
ret = {}
conn = get_conn(service='SoftLayer_Product_Package')
@ -121,12 +127,18 @@ def avail_locations():
return ret
def avail_sizes():
def avail_sizes(call=None):
'''
Return a dict of all available VM sizes on the cloud provider with
relevant data. This data is provided in three dicts.
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_sizes function must be called with '
'-f or --function, or with the --list-sizes option'
)
ret = {
'Bare Metal Instance': {
'1921': {
@ -158,10 +170,16 @@ def avail_sizes():
return ret
def avail_images():
def avail_images(call=None):
'''
Return a dict of all available VM images on the cloud provider.
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_images function must be called with '
'-f or --function, or with the --list-images option'
)
ret = {'Operating System': {
'13962': {
'id': '13962',

View File

@ -98,10 +98,16 @@ def get_conn(service='SoftLayer_Virtual_Guest'):
return client[service]
def avail_locations():
def avail_locations(call=None):
'''
List all available locations
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_locations function must be called with '
'-f or --function, or with the --list-locations option'
)
ret = {}
conn = get_conn()
response = conn.getCreateObjectOptions()
@ -114,12 +120,17 @@ def avail_locations():
return ret
def avail_sizes():
def avail_sizes(call=None):
'''
Return a dict of all available VM sizes on the cloud provider with
relevant data. This data is provided in three dicts.
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_sizes function must be called with '
'-f or --function, or with the --list-sizes option'
)
ret = {
'block devices': {},
'memory': {},
@ -147,10 +158,16 @@ def avail_sizes():
return ret
def avail_images():
def avail_images(call=None):
'''
Return a dict of all available VM images on the cloud provider.
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_images function must be called with '
'-f or --function, or with the --list-images option'
)
ret = {}
conn = get_conn()
response = conn.getCreateObjectOptions()

View File

@ -91,11 +91,17 @@ def ssh_pub(vm_):
return SSHKeyDeployment(open(ssh).read())
def avail_locations(conn=None):
def avail_locations(conn=None, call=None):
'''
Return a dict of all available VM locations on the cloud provider with
relevant data
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_locations function must be called with '
'-f or --function, or with the --list-locations option'
)
if not conn:
conn = get_conn() # pylint: disable=E0602
@ -122,11 +128,17 @@ def avail_locations(conn=None):
return ret
def avail_images(conn=None):
def avail_images(conn=None, call=None):
'''
Return a dict of all available VM images on the cloud provider with
relevant data
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_images function must be called with '
'-f or --function, or with the --list-images option'
)
if not conn:
conn = get_conn() # pylint: disable=E0602
@ -151,11 +163,17 @@ def avail_images(conn=None):
return ret
def avail_sizes(conn=None):
def avail_sizes(conn=None, call=None):
'''
Return a dict of all available VM images on the cloud provider with
relevant data
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_sizes function must be called with '
'-f or --function, or with the --list-sizes option'
)
if not conn:
conn = get_conn() # pylint: disable=E0602