@@ -39,65 +39,42 @@ def cli(env, identifier, passwords=False, price=False):
3939 table .add_row (['domain' , result ['domain' ]])
4040 table .add_row (['fqdn' , result ['fullyQualifiedDomainName' ]])
4141 table .add_row (['status' , formatting .FormattedItem (
42- result ['status' ]['keyName' ] or formatting . blank () ,
43- result ['status' ]['name' ] or formatting . blank ()
42+ result ['status' ]['keyName' ],
43+ result ['status' ]['name' ]
4444 )])
4545 table .add_row (['state' , formatting .FormattedItem (
4646 utils .lookup (result , 'powerState' , 'keyName' ),
4747 utils .lookup (result , 'powerState' , 'name' ),
4848 )])
4949 table .add_row (['active_transaction' , formatting .active_txn (result )])
50- table .add_row (['datacenter' ,
51- result ['datacenter' ]['name' ] or formatting .blank ()])
50+ table .add_row (['datacenter' , result ['datacenter' ]['name' ] or formatting .blank ()])
5251 _cli_helper_dedicated_host (env , result , table )
5352 operating_system = utils .lookup (result ,
5453 'operatingSystem' ,
5554 'softwareLicense' ,
5655 'softwareDescription' ) or {}
57- table .add_row (['os' , operating_system .get ('name' ) or formatting .blank ()])
58- table .add_row (['os_version' ,
59- operating_system .get ('version' ) or formatting .blank ()])
56+ table .add_row (['os' , operating_system .get ('name' , '-' )])
57+ table .add_row (['os_version' , operating_system .get ('version' , '-' )])
6058 table .add_row (['cores' , result ['maxCpu' ]])
6159 table .add_row (['memory' , formatting .mb_to_gb (result ['maxMemory' ])])
62- table .add_row (['public_ip' ,
63- result ['primaryIpAddress' ] or formatting .blank ()])
64- table .add_row (['private_ip' ,
65- result ['primaryBackendIpAddress' ] or formatting .blank ()])
60+ table .add_row (['public_ip' , result .get ('primaryIpAddress' , '-' )])
61+ table .add_row (['private_ip' , result .get ('primaryBackendIpAddress' , '-' )])
6662 table .add_row (['private_only' , result ['privateNetworkOnlyFlag' ]])
6763 table .add_row (['private_cpu' , result ['dedicatedAccountHostOnlyFlag' ]])
6864 table .add_row (['created' , result ['createDate' ]])
6965 table .add_row (['modified' , result ['modifyDate' ]])
70- if utils .lookup (result , 'billingItem' ) != []:
71- table .add_row (['owner' , formatting .FormattedItem (
72- utils .lookup (result , 'billingItem' , 'orderItem' ,
73- 'order' , 'userRecord' ,
74- 'username' ) or formatting .blank (),
75- )])
76- else :
77- table .add_row (['owner' , formatting .blank ()])
7866
79- vlan_table = formatting .Table (['type' , 'number' , 'id' ])
80- for vlan in result ['networkVlans' ]:
81- vlan_table .add_row ([
82- vlan ['networkSpace' ], vlan ['vlanNumber' ], vlan ['id' ]])
83- table .add_row (['vlans' , vlan_table ])
67+ table .add_row (_get_owner_row (result ))
68+ table .add_row (_get_vlan_table (result ))
8469
85- if result .get ('networkComponents' ):
86- secgroup_table = formatting .Table (['interface' , 'id' , 'name' ])
87- has_secgroups = False
88- for comp in result .get ('networkComponents' ):
89- interface = 'PRIVATE' if comp ['port' ] == 0 else 'PUBLIC'
90- for binding in comp ['securityGroupBindings' ]:
91- has_secgroups = True
92- secgroup = binding ['securityGroup' ]
93- secgroup_table .add_row ([
94- interface , secgroup ['id' ],
95- secgroup .get ('name' ) or formatting .blank ()])
96- if has_secgroups :
97- table .add_row (['security_groups' , secgroup_table ])
70+ bandwidth = vsi .get_bandwidth_allocation (vs_id )
71+ table .add_row (['Bandwidth' , _bw_table (bandwidth )])
72+
73+ security_table = _get_security_table (result )
74+ if security_table is not None :
75+ table .add_row (['security_groups' , security_table ])
9876
99- if result .get ('notes' ):
100- table .add_row (['notes' , result ['notes' ]])
77+ table .add_row (['notes' , result .get ('notes' , '-' )])
10178
10279 if price :
10380 total_price = utils .lookup (result ,
@@ -145,6 +122,20 @@ def cli(env, identifier, passwords=False, price=False):
145122 env .fout (table )
146123
147124
125+ def _bw_table (bw_data ):
126+ """Generates a bandwidth useage table"""
127+ table = formatting .Table (['Type' , 'In GB' , 'Out GB' , 'Allotment' ])
128+ for bw_point in bw_data .get ('useage' ):
129+ bw_type = 'Private'
130+ allotment = 'N/A'
131+ if bw_point ['type' ]['alias' ] == 'PUBLIC_SERVER_BW' :
132+ bw_type = 'Public'
133+ allotment = bw_data ['allotment' ].get ('amount' , '-' )
134+
135+ table .add_row ([bw_type , bw_point ['amountIn' ], bw_point ['amountOut' ], allotment ])
136+ return table
137+
138+
148139def _cli_helper_dedicated_host (env , result , table ):
149140 """Get details on dedicated host for a virtual server."""
150141
@@ -160,3 +151,40 @@ def _cli_helper_dedicated_host(env, result, table):
160151 dedicated_host = {}
161152 table .add_row (['dedicated_host' ,
162153 dedicated_host .get ('name' ) or formatting .blank ()])
154+
155+
156+ def _get_owner_row (result ):
157+ """Formats and resturns the Owner row"""
158+
159+ if utils .lookup (result , 'billingItem' ) != []:
160+ owner = utils .lookup (result , 'billingItem' , 'orderItem' , 'order' , 'userRecord' , 'username' )
161+ else :
162+ owner = formatting .blank ()
163+ return (['owner' , owner ])
164+
165+
166+ def _get_vlan_table (result ):
167+ """Formats and resturns a vlan table"""
168+
169+ vlan_table = formatting .Table (['type' , 'number' , 'id' ])
170+ for vlan in result ['networkVlans' ]:
171+ vlan_table .add_row ([
172+ vlan ['networkSpace' ], vlan ['vlanNumber' ], vlan ['id' ]])
173+ return ['vlans' , vlan_table ]
174+
175+
176+ def _get_security_table (result ):
177+ secgroup_table = formatting .Table (['interface' , 'id' , 'name' ])
178+ has_secgroups = False
179+
180+ if result .get ('networkComponents' ):
181+ for comp in result .get ('networkComponents' ):
182+ interface = 'PRIVATE' if comp ['port' ] == 0 else 'PUBLIC'
183+ for binding in comp ['securityGroupBindings' ]:
184+ has_secgroups = True
185+ secgroup = binding ['securityGroup' ]
186+ secgroup_table .add_row ([interface , secgroup ['id' ], secgroup .get ('name' , '-' )])
187+ if has_secgroups :
188+ return secgroup_table
189+ else :
190+ return None
0 commit comments