Skip to content

Commit 2146852

Browse files
authored
Merge branch 'master' into rebase-softlayer-07-22-2019
2 parents 82e24c7 + 7940e1b commit 2146852

2 files changed

Lines changed: 76 additions & 75 deletions

File tree

SoftLayer/CLI/virt/create.py

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -70,84 +70,85 @@ def _update_with_like_args(ctx, _, value):
7070

7171

7272
def _parse_create_args(client, args):
73-
"""Converts CLI arguments to args for VSManager.create_instance.
73+
"""Converts CLI arguments to args for VSManager.create_instances.
7474
7575
:param dict args: CLI arguments
7676
"""
77-
data = {
78-
"hourly": args.get('billing', 'hourly') == 'hourly',
79-
"cpus": args.get('cpu', None),
80-
"ipv6": args.get('ipv6', None),
81-
"disks": args.get('disk', None),
82-
"os_code": args.get('os', None),
83-
"memory": args.get('memory', None),
84-
"flavor": args.get('flavor', None),
85-
"domain": args.get('domain', None),
86-
"host_id": args.get('host_id', None),
87-
"private": args.get('private', None),
88-
"transient": args.get('transient', None),
89-
"hostname": args.get('hostname', None),
90-
"nic_speed": args.get('network', None),
91-
"boot_mode": args.get('boot_mode', None),
92-
"dedicated": args.get('dedicated', None),
93-
"post_uri": args.get('postinstall', None),
94-
"datacenter": args.get('datacenter', None),
95-
"public_vlan": args.get('vlan_public', None),
96-
"private_vlan": args.get('vlan_private', None),
97-
"public_subnet": args.get('subnet_public', None),
98-
"private_subnet": args.get('subnet_private', None),
99-
}
100-
101-
# The primary disk is included in the flavor and the local_disk flag is not needed
102-
# Setting it to None prevents errors from the flag not matching the flavor
103-
if not args.get('san') and args.get('flavor'):
104-
data['local_disk'] = None
105-
else:
106-
data['local_disk'] = not args.get('san')
107-
108-
if args.get('image'):
109-
if args.get('image').isdigit():
110-
image_mgr = SoftLayer.ImageManager(client)
111-
image_details = image_mgr.get_image(args.get('image'),
112-
mask="id,globalIdentifier")
113-
data['image_id'] = image_details['globalIdentifier']
77+
78+
config_list = []
79+
80+
for hostname in args['hostnames'].split(','):
81+
data = {
82+
"hourly": args.get('billing', 'hourly') == 'hourly',
83+
"cpus": args.get('cpu', None),
84+
"ipv6": args.get('ipv6', None),
85+
"disks": args.get('disk', None),
86+
"os_code": args.get('os', None),
87+
"memory": args.get('memory', None),
88+
"flavor": args.get('flavor', None),
89+
"domain": args.get('domain', None),
90+
"host_id": args.get('host_id', None),
91+
"private": args.get('private', None),
92+
"transient": args.get('transient', None),
93+
"hostname": args.get('hostname', None),
94+
"nic_speed": args.get('network', None),
95+
"boot_mode": args.get('boot_mode', None),
96+
"dedicated": args.get('dedicated', None),
97+
"post_uri": args.get('postinstall', None),
98+
"datacenter": args.get('datacenter', None),
99+
"public_vlan": args.get('vlan_public', None),
100+
"private_vlan": args.get('vlan_private', None),
101+
"public_subnet": args.get('subnet_public', None),
102+
"private_subnet": args.get('subnet_private', None),
103+
}
104+
105+
# The primary disk is included in the flavor and the local_disk flag is not needed
106+
# Setting it to None prevents errors from the flag not matching the flavor
107+
if not args.get('san') and args.get('flavor'):
108+
data['local_disk'] = None
114109
else:
115-
data['image_id'] = args['image']
116-
117-
if args.get('userdata'):
118-
data['userdata'] = args['userdata']
119-
elif args.get('userfile'):
120-
with open(args['userfile'], 'r') as userfile:
121-
data['userdata'] = userfile.read()
110+
data['local_disk'] = not args.get('san')
111+
112+
if args.get('image'):
113+
if args.get('image').isdigit():
114+
image_mgr = SoftLayer.ImageManager(client)
115+
image_details = image_mgr.get_image(args.get('image'),
116+
mask="id,globalIdentifier")
117+
data['image_id'] = image_details['globalIdentifier']
118+
else:
119+
data['local_disk'] = not args['san']
120+
121+
if args.get('userdata'):
122+
data['userdata'] = args['userdata']
123+
elif args.get('userfile'):
124+
with open(args['userfile'], 'r') as userfile:
125+
data['userdata'] = userfile.read()
122126

123127
# Get the SSH keys
124-
if args.get('key'):
125-
keys = []
126-
for key in args.get('key'):
127-
resolver = SoftLayer.SshKeyManager(client).resolve_ids
128-
key_id = helpers.resolve_id(resolver, key, 'SshKey')
129-
keys.append(key_id)
130-
data['ssh_keys'] = keys
128+
if args.get('key'):
129+
keys = []
130+
for key in args.get('key'):
131+
resolver = SoftLayer.SshKeyManager(client).resolve_ids
132+
key_id = helpers.resolve_id(resolver, key, 'SshKey')
133+
keys.append(key_id)
134+
data['ssh_keys'] = keys
131135

132-
if args.get('public_security_group'):
133-
pub_groups = args.get('public_security_group')
134-
data['public_security_groups'] = [group for group in pub_groups]
136+
if args.get('public_security_group'):
137+
pub_groups = args.get('public_security_group')
138+
data['public_security_groups'] = [group for group in pub_groups]
139+
if args.get('private_security_group'):
140+
priv_groups = args.get('private_security_group')
141+
data['private_security_groups'] = [group for group in priv_groups]
135142

136-
if args.get('private_security_group'):
137-
priv_groups = args.get('private_security_group')
138-
data['private_security_groups'] = [group for group in priv_groups]
143+
if args.get('tag'):
144+
data['tags'] = ','.join(args['tag'])
139145

140-
if args.get('tag', False):
141-
data['tags'] = ','.join(args['tag'])
146+
if args.get('placementgroup'):
147+
resolver = SoftLayer.managers.PlacementManager(client).resolve_ids
148+
data['placement_id'] = helpers.resolve_id(resolver, args.get('placementgroup'), 'PlacementGroup')
142149

143-
if args.get('host_id'):
144-
data['host_id'] = args['host_id']
145-
146-
if args.get('placementgroup'):
147-
resolver = SoftLayer.managers.PlacementManager(client).resolve_ids
148-
data['placement_id'] = helpers.resolve_id(resolver, args.get('placementgroup'), 'PlacementGroup')
149-
150-
return data
150+
config_list.append(data)
151+
return config_list
151152

152153

153154
@click.command(epilog="See 'slcli vs create-options' for valid options")
@@ -258,12 +259,13 @@ def cli(env, **args):
258259
env.fout('Successfully exported options to a template file.')
259260

260261
else:
261-
result = vsi.order_guest(create_args, test)
262-
output = _build_receipt_table(result, args.get('billing'), test)
262+
for create_args in config_list:
263+
result = vsi.order_guest(create_args, test)
264+
output = _build_receipt_table(result, args.get('billing'), test)
263265

264-
if do_create:
265-
env.fout(_build_guest_table(result))
266-
env.fout(output)
266+
if do_create:
267+
env.fout(_build_guest_table(result))
268+
env.fout(output)
267269

268270
if args.get('wait'):
269271
virtual_guests = utils.lookup(result, 'orderDetails', 'virtualGuests')
@@ -273,6 +275,7 @@ def cli(env, **args):
273275
if ready is False:
274276
env.out(env.fmt(output))
275277
raise exceptions.CLIHalt(code=1)
278+
276279
if args['output_json']:
277280
env.fout(json.dumps({'statuses': result}))
278281
else:
@@ -311,7 +314,6 @@ def _build_receipt_table(result, billing="hourly", test=False):
311314
table.add_row(["%.3f" % total, "Total %s cost" % billing])
312315
return table
313316

314-
315317
def _build_guest_table(result):
316318
table = formatting.Table(['ID', 'FQDN', 'guid', 'Order Date'])
317319
table.align['name'] = 'r'

SoftLayer/managers/dedicated_host.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ def _delete_guest(self, guest_id):
602602
self.guest.deleteObject(id=guest_id)
603603
except SoftLayer.SoftLayerAPIError as e:
604604
msg = 'Exception: ' + e.faultString
605-
606605
return msg
607606

608607
# @retry(logger=LOGGER)

0 commit comments

Comments
 (0)