@@ -89,53 +89,60 @@ def order_options(env, datacenter):
89
89
net_mgr = SoftLayer .NetworkManager (env .client )
90
90
package = mgr .lbaas_order_options ()
91
91
92
- for region in package ['regions' ]:
93
- dc_name = utils .lookup (region , 'location' , 'location' , 'name' )
94
-
95
- # Skip locations if they are not the one requested.
96
- if datacenter and dc_name != datacenter :
97
- continue
98
- this_table = formatting .Table (
99
- ['Prices' , 'Private Subnets' ],
100
- title = "{}: {}" .format (region ['keyname' ], region ['description' ])
101
- )
102
-
103
- l_groups = []
104
- for group in region ['location' ]['location' ]['groups' ]:
105
- l_groups .append (group .get ('id' ))
106
-
107
- # Price lookups
108
- prices = []
109
- price_table = formatting .KeyValueTable (['KeyName' , 'Cost' ])
110
- for item in package ['items' ]:
111
- i_price = {'keyName' : item ['keyName' ]}
112
- for price in item .get ('prices' , []):
113
- if not price .get ('locationGroupId' ):
114
- i_price ['default_price' ] = price .get ('hourlyRecurringFee' )
115
- elif price .get ('locationGroupId' ) in l_groups :
116
- i_price ['region_price' ] = price .get ('hourlyRecurringFee' )
117
- prices .append (i_price )
118
- for price in prices :
119
- if price .get ('region_price' ):
120
- price_table .add_row ([price .get ('keyName' ), price .get ('region_price' )])
121
- else :
122
- price_table .add_row ([price .get ('keyName' ), price .get ('default_price' )])
123
-
124
- # Vlan/Subnet Lookups
125
- mask = "mask[networkVlan,podName,addressSpace]"
126
- subnets = net_mgr .list_subnets (datacenter = dc_name , network_space = 'PRIVATE' , mask = mask )
127
- subnet_table = formatting .Table (['Id' , 'Subnet' , 'Vlan' ])
128
-
129
- for subnet in subnets :
130
- # Only show these types, easier to filter here than in an API call.
131
- if subnet .get ('subnetType' ) != 'PRIMARY' and subnet .get ('subnetType' ) != 'ADDITIONAL_PRIMARY' :
92
+ if not datacenter :
93
+ data_table = formatting .KeyValueTable (['Datacenters' , 'City' ])
94
+ for region in package ['regions' ]:
95
+ data_table .add_row ([region ['description' ].split ('-' )[0 ], region ['description' ].split ('-' )[1 ]])
96
+ # print(region)
97
+ env .fout (data_table )
98
+ click .secho ("Use `slcli lb order-options --datacenter <DC>` "
99
+ "to find pricing information and private subnets for that specific site." )
100
+
101
+ else :
102
+ for region in package ['regions' ]:
103
+ dc_name = utils .lookup (region , 'location' , 'location' , 'name' )
104
+
105
+ # Skip locations if they are not the one requested.
106
+ if datacenter and dc_name != datacenter .lower ():
132
107
continue
133
- space = "{}/{}" .format (subnet .get ('networkIdentifier' ), subnet .get ('cidr' ))
134
- vlan = "{}.{}" .format (subnet ['podName' ], subnet ['networkVlan' ]['vlanNumber' ])
135
- subnet_table .add_row ([subnet .get ('id' ), space , vlan ])
136
- this_table .add_row ([price_table , subnet_table ])
137
108
138
- env .fout (this_table )
109
+ l_groups = []
110
+ for group in region ['location' ]['location' ]['groups' ]:
111
+ l_groups .append (group .get ('id' ))
112
+
113
+ # Price lookups
114
+ prices = []
115
+ price_table = formatting .KeyValueTable (['KeyName' , 'Cost' ], title = 'Prices' )
116
+ for item in package ['items' ]:
117
+ i_price = {'keyName' : item ['keyName' ]}
118
+ for price in item .get ('prices' , []):
119
+ if not price .get ('locationGroupId' ):
120
+ i_price ['default_price' ] = price .get ('hourlyRecurringFee' )
121
+ elif price .get ('locationGroupId' ) in l_groups :
122
+ i_price ['region_price' ] = price .get ('hourlyRecurringFee' )
123
+ prices .append (i_price )
124
+ for price in prices :
125
+ if price .get ('region_price' ):
126
+ price_table .add_row ([price .get ('keyName' ), price .get ('region_price' )])
127
+ else :
128
+ price_table .add_row ([price .get ('keyName' ), price .get ('default_price' )])
129
+
130
+ # Vlan/Subnet Lookups
131
+ mask = "mask[networkVlan,podName,addressSpace]"
132
+ subnets = net_mgr .list_subnets (datacenter = dc_name , network_space = 'PRIVATE' , mask = mask )
133
+ subnet_table = formatting .Table (['Id' , 'Subnet' , 'Vlan' ], title = 'Private subnet' )
134
+
135
+ for subnet in subnets :
136
+ # Only show these types, easier to filter here than in an API call.
137
+ if subnet .get ('subnetType' ) != 'PRIMARY' and \
138
+ subnet .get ('subnetType' ) != 'ADDITIONAL_PRIMARY' :
139
+ continue
140
+ space = "{}/{}" .format (subnet .get ('networkIdentifier' ), subnet .get ('cidr' ))
141
+ vlan = "{}.{}" .format (subnet ['podName' ], subnet ['networkVlan' ]['vlanNumber' ])
142
+ subnet_table .add_row ([subnet .get ('id' ), space , vlan ])
143
+
144
+ env .fout (price_table )
145
+ env .fout (subnet_table )
139
146
140
147
141
148
@click .command ()
0 commit comments