33
44import click
55
6- import SoftLayer
76from SoftLayer .CLI import environment
87from SoftLayer .CLI import formatting
98from SoftLayer .CLI import helpers
9+ from SoftLayer .CLI .virt .create import _parse_create_args as _parse_create_args
1010from SoftLayer .CLI .virt .create import _update_with_like_args as _update_with_like_args
1111from SoftLayer .managers .vs_capacity import CapacityManager as CapacityManager
1212
1313
14- from pprint import pprint as pp
15-
16-
17-
18- def _parse_create_args (client , args ):
19- """Parses CLI arguments into a single data structure to be used by vs_capacity::create_guest.
20-
21- :param dict args: CLI arguments
22- """
23- data = {
24- "hourly" : True ,
25- "domain" : args ['domain' ],
26- "hostname" : args ['hostname' ],
27- "private" : args ['private' ],
28- "disks" : args ['disk' ],
29- "boot_mode" : args .get ('boot_mode' , None ),
30- "local_disk" : None
31- }
32- if args .get ('os' ):
33- data ['os_code' ] = args ['os' ]
34-
35- if args .get ('image' ):
36- if args .get ('image' ).isdigit ():
37- image_mgr = SoftLayer .ImageManager (client )
38- image_details = image_mgr .get_image (args .get ('image' ),
39- mask = "id,globalIdentifier" )
40- data ['image_id' ] = image_details ['globalIdentifier' ]
41- else :
42- data ['image_id' ] = args ['image' ]
43-
44- if args .get ('network' ):
45- data ['nic_speed' ] = args .get ('network' )
46-
47- if args .get ('userdata' ):
48- data ['userdata' ] = args ['userdata' ]
49- elif args .get ('userfile' ):
50- with open (args ['userfile' ], 'r' ) as userfile :
51- data ['userdata' ] = userfile .read ()
52-
53- if args .get ('postinstall' ):
54- data ['post_uri' ] = args .get ('postinstall' )
55-
56- # Get the SSH keys
57- if args .get ('key' ):
58- keys = []
59- for key in args .get ('key' ):
60- resolver = SoftLayer .SshKeyManager (client ).resolve_ids
61- key_id = helpers .resolve_id (resolver , key , 'SshKey' )
62- keys .append (key_id )
63- data ['ssh_keys' ] = keys
64-
65- if args .get ('vlan_public' ):
66- data ['public_vlan' ] = args ['vlan_public' ]
67-
68- if args .get ('vlan_private' ):
69- data ['private_vlan' ] = args ['vlan_private' ]
70-
71- data ['public_subnet' ] = args .get ('subnet_public' , None )
72-
73- data ['private_subnet' ] = args .get ('subnet_private' , None )
74-
75- if args .get ('public_security_group' ):
76- pub_groups = args .get ('public_security_group' )
77- data ['public_security_groups' ] = [group for group in pub_groups ]
78-
79- if args .get ('private_security_group' ):
80- priv_groups = args .get ('private_security_group' )
81- data ['private_security_groups' ] = [group for group in priv_groups ]
82-
83- if args .get ('tag' ):
84- data ['tags' ] = ',' .join (args ['tag' ])
85-
86- if args .get ('host_id' ):
87- data ['host_id' ] = args ['host_id' ]
88-
89- if args .get ('ipv6' ):
90- data ['ipv6' ] = True
91-
92- data ['primary_disk' ] = args .get ('primary_disk' )
93-
94- return data
95-
96-
9714@click .command ()
9815@click .option ('--capacity-id' , type = click .INT , help = "Reserve capacity Id to provision this guest into." )
99- @click .option ('--primary-disk' , type = click .Choice (['25' ,'100' ]), default = '25' , help = "Size of the main drive." )
16+ @click .option ('--primary-disk' , type = click .Choice (['25' , '100' ]), default = '25' , help = "Size of the main drive." )
10017@click .option ('--hostname' , '-H' , required = True , prompt = True , help = "Host portion of the FQDN." )
10118@click .option ('--domain' , '-D' , required = True , prompt = True , help = "Domain portion of the FQDN." )
10219@click .option ('--os' , '-o' , help = "OS install code. Tip: you can specify <OS>_LATEST." )
@@ -113,12 +30,15 @@ def _parse_create_args(client, args):
11330@helpers .multi_option ('--tag' , '-g' , help = "Tags to add to the instance." )
11431@click .option ('--userdata' , '-u' , help = "User defined metadata string." )
11532@click .option ('--ipv6' , is_flag = True , help = "Adds an IPv6 address to this guest" )
116- @click .option ('--test' , is_flag = True ,
33+ @click .option ('--test' , is_flag = True ,
11734 help = "Test order, will return the order container, but not actually order a server." )
11835@environment .pass_env
11936def cli (env , ** args ):
12037 """Allows for creating a virtual guest in a reserved capacity."""
12138 create_args = _parse_create_args (env .client , args )
39+ if args .get ('ipv6' ):
40+ create_args ['ipv6' ] = True
41+ create_args ['primary_disk' ] = args .get ('primary_disk' )
12242 manager = CapacityManager (env .client )
12343 capacity_id = args .get ('capacity_id' )
12444 test = args .get ('test' )
@@ -141,4 +61,3 @@ def _build_receipt(result, test=False):
14161 for item in prices :
14262 table .add_row ([item ['id' ], item ['item' ]['description' ]])
14363 return table
144-
0 commit comments