8
8
import SoftLayer
9
9
from SoftLayer .CLI import environment
10
10
from SoftLayer .CLI import formatting
11
+ from SoftLayer import utils
11
12
12
13
13
14
@click .command ()
@@ -25,35 +26,63 @@ def cli(env):
25
26
# Datacenters
26
27
datacenters = [dc ['template' ]['datacenter' ]['name' ]
27
28
for dc in result ['datacenters' ]]
29
+ datacenters = sorted (datacenters )
30
+
28
31
table .add_row (['datacenter' ,
29
32
formatting .listing (datacenters , separator = '\n ' )])
30
33
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
35
41
36
- ded_cpu = [x for x in result ['processors' ]
37
- if x ['template' ].get ('dedicatedAccountHostOnlyFlag' ,
38
- False )]
42
+ flavors .append (flavor_key_name )
39
43
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 ' )])
45
47
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' ])
48
54
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 = ',' )])
51
71
52
72
# 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 )
54
79
table .add_row (['memory' ,
55
80
formatting .listing (memory , separator = ',' )])
56
81
82
+ ded_host_memory = sorted (ded_host_memory )
83
+ table .add_row (['memory (dedicated host)' ,
84
+ formatting .listing (ded_host_memory , separator = ',' )])
85
+
57
86
# Operating Systems
58
87
op_sys = [o ['template' ]['operatingSystemReferenceCode' ] for o in
59
88
result ['operatingSystems' ]]
@@ -73,7 +102,14 @@ def add_cpus_row(cpu_options, name):
73
102
74
103
# Disk
75
104
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 )]
77
113
78
114
san_disks = [x for x in result ['blockDevices' ]
79
115
if not x ['template' ].get ('localDiskFlag' , False )]
@@ -95,17 +131,37 @@ def add_block_rows(disks, name):
95
131
formatting .listing (simple [label ],
96
132
separator = ',' )])
97
133
98
- add_block_rows (local_disks , 'local' )
99
134
add_block_rows (san_disks , 'san' )
135
+ add_block_rows (local_disks , 'local' )
136
+ add_block_rows (ded_host_local_disks , 'local (dedicated host)' )
100
137
101
138
# Network
102
139
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 )
106
159
107
160
speeds = sorted (speeds )
108
-
109
161
table .add_row (['nic' , formatting .listing (speeds , separator = ',' )])
110
162
163
+ ded_host_speeds = sorted (ded_host_speeds )
164
+ table .add_row (['nic (dedicated host)' ,
165
+ formatting .listing (ded_host_speeds , separator = ',' )])
166
+
111
167
env .fout (table )
0 commit comments