88import SoftLayer
99from SoftLayer .CLI import environment
1010from SoftLayer .CLI import formatting
11+ from SoftLayer import utils
1112
1213
1314@click .command ()
@@ -25,35 +26,63 @@ def cli(env):
2526 # Datacenters
2627 datacenters = [dc ['template' ]['datacenter' ]['name' ]
2728 for dc in result ['datacenters' ]]
29+ datacenters = sorted (datacenters )
30+
2831 table .add_row (['datacenter' ,
2932 formatting .listing (datacenters , separator = '\n ' )])
3033
31- # CPUs
32- standard_cpu = [x for x in result ['processors' ]
33- if not x ['template' ].get (
34- 'dedicatedAccountHostOnlyFlag' , False )]
34+ def _add_flavor_rows (flavor_key , flavor_label , flavor_options ):
35+ flavors = []
36+
37+ for flavor_option in flavor_options :
38+ flavor_key_name = utils .lookup (flavor_option , 'flavor' , 'keyName' )
39+ if not flavor_key_name .startswith (flavor_key ):
40+ continue
3541
36- ded_cpu = [x for x in result ['processors' ]
37- if x ['template' ].get ('dedicatedAccountHostOnlyFlag' ,
38- False )]
42+ flavors .append (flavor_key_name )
3943
40- def add_cpus_row (cpu_options , name ):
41- """Add CPU rows to the table."""
42- cpus = []
43- for cpu_option in cpu_options :
44- cpus .append (str (cpu_option ['template' ]['startCpus' ]))
44+ if len (flavors ) > 0 :
45+ table .add_row (['flavors (%s)' % flavor_label ,
46+ formatting .listing (flavors , separator = '\n ' )])
4547
46- table .add_row (['cpus (%s)' % name ,
47- formatting .listing (cpus , separator = ',' )])
48+ if result .get ('flavors' , None ):
49+ _add_flavor_rows ('B1' , 'balanced' , result ['flavors' ])
50+ _add_flavor_rows ('BL1' , 'balanced local - hdd' , result ['flavors' ])
51+ _add_flavor_rows ('BL2' , 'balanced local - ssd' , result ['flavors' ])
52+ _add_flavor_rows ('C1' , 'compute' , result ['flavors' ])
53+ _add_flavor_rows ('M1' , 'memory' , result ['flavors' ])
4854
49- add_cpus_row (ded_cpu , 'private' )
50- add_cpus_row (standard_cpu , 'standard' )
55+ # CPUs
56+ standard_cpus = [int (x ['template' ]['startCpus' ]) for x in result ['processors' ]
57+ if not x ['template' ].get ('dedicatedAccountHostOnlyFlag' ,
58+ False )
59+ and not x ['template' ].get ('dedicatedHost' , None )]
60+ ded_cpus = [int (x ['template' ]['startCpus' ]) for x in result ['processors' ]
61+ if x ['template' ].get ('dedicatedAccountHostOnlyFlag' , False )]
62+ ded_host_cpus = [int (x ['template' ]['startCpus' ]) for x in result ['processors' ]
63+ if x ['template' ].get ('dedicatedHost' , None )]
64+
65+ standard_cpus = sorted (standard_cpus )
66+ table .add_row (['cpus (standard)' , formatting .listing (standard_cpus , separator = ',' )])
67+ ded_cpus = sorted (ded_cpus )
68+ table .add_row (['cpus (dedicated)' , formatting .listing (ded_cpus , separator = ',' )])
69+ ded_host_cpus = sorted (ded_host_cpus )
70+ table .add_row (['cpus (dedicated host)' , formatting .listing (ded_host_cpus , separator = ',' )])
5171
5272 # Memory
53- memory = [str (m ['template' ]['maxMemory' ]) for m in result ['memory' ]]
73+ memory = [int (m ['template' ]['maxMemory' ]) for m in result ['memory' ]
74+ if not m ['itemPrice' ].get ('dedicatedHostInstanceFlag' , False )]
75+ ded_host_memory = [int (m ['template' ]['maxMemory' ]) for m in result ['memory' ]
76+ if m ['itemPrice' ].get ('dedicatedHostInstanceFlag' , False )]
77+
78+ memory = sorted (memory )
5479 table .add_row (['memory' ,
5580 formatting .listing (memory , separator = ',' )])
5681
82+ ded_host_memory = sorted (ded_host_memory )
83+ table .add_row (['memory (dedicated host)' ,
84+ formatting .listing (ded_host_memory , separator = ',' )])
85+
5786 # Operating Systems
5887 op_sys = [o ['template' ]['operatingSystemReferenceCode' ] for o in
5988 result ['operatingSystems' ]]
@@ -73,7 +102,14 @@ def add_cpus_row(cpu_options, name):
73102
74103 # Disk
75104 local_disks = [x for x in result ['blockDevices' ]
76- if x ['template' ].get ('localDiskFlag' , False )]
105+ if x ['template' ].get ('localDiskFlag' , False )
106+ and not x ['itemPrice' ].get ('dedicatedHostInstanceFlag' ,
107+ False )]
108+
109+ ded_host_local_disks = [x for x in result ['blockDevices' ]
110+ if x ['template' ].get ('localDiskFlag' , False )
111+ and x ['itemPrice' ].get ('dedicatedHostInstanceFlag' ,
112+ False )]
77113
78114 san_disks = [x for x in result ['blockDevices' ]
79115 if not x ['template' ].get ('localDiskFlag' , False )]
@@ -95,17 +131,37 @@ def add_block_rows(disks, name):
95131 formatting .listing (simple [label ],
96132 separator = ',' )])
97133
98- add_block_rows (local_disks , 'local' )
99134 add_block_rows (san_disks , 'san' )
135+ add_block_rows (local_disks , 'local' )
136+ add_block_rows (ded_host_local_disks , 'local (dedicated host)' )
100137
101138 # Network
102139 speeds = []
103- for comp in result ['networkComponents' ]:
104- speed = comp ['template' ]['networkComponents' ][0 ]['maxSpeed' ]
105- speeds .append (str (speed ))
140+ ded_host_speeds = []
141+ for option in result ['networkComponents' ]:
142+ template = option .get ('template' , None )
143+ price = option .get ('itemPrice' , None )
144+
145+ if not template or not price \
146+ or not template .get ('networkComponents' , None ):
147+ continue
148+
149+ if not template ['networkComponents' ][0 ] \
150+ or not template ['networkComponents' ][0 ].get ('maxSpeed' , None ):
151+ continue
152+
153+ max_speed = str (template ['networkComponents' ][0 ]['maxSpeed' ])
154+ if price .get ('dedicatedHostInstanceFlag' , False ) \
155+ and max_speed not in ded_host_speeds :
156+ ded_host_speeds .append (max_speed )
157+ elif max_speed not in speeds :
158+ speeds .append (max_speed )
106159
107160 speeds = sorted (speeds )
108-
109161 table .add_row (['nic' , formatting .listing (speeds , separator = ',' )])
110162
163+ ded_host_speeds = sorted (ded_host_speeds )
164+ table .add_row (['nic (dedicated host)' ,
165+ formatting .listing (ded_host_speeds , separator = ',' )])
166+
111167 env .fout (table )
0 commit comments