5252@click .option ('--hourly' , is_flag = True , help = 'Show only hourly instances' )
5353@click .option ('--monthly' , is_flag = True , help = 'Show only monthly instances' )
5454@click .option ('--transient' , help = 'Filter by transient instances' , type = click .BOOL )
55+ @click .option ('--hardware' , is_flag = True , default = False , help = 'Show the all VSI related to hardware' )
56+ @click .option ('--all-guests' , is_flag = True , default = False , help = 'Show the all VSI and hardware VSIs' )
5557@helpers .multi_option ('--tag' , help = 'Filter by tags' )
5658@click .option ('--sortby' ,
5759 help = 'Column to sort by' ,
6971 show_default = True )
7072@environment .pass_env
7173def cli (env , sortby , cpu , domain , datacenter , hostname , memory , network ,
72- hourly , monthly , tag , columns , limit , transient ):
74+ hourly , monthly , tag , columns , limit , transient , hardware , all_guests ):
7375 """List virtual servers."""
7476
7577 vsi = SoftLayer .VSManager (env .client )
@@ -88,27 +90,29 @@ def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network,
8890
8991 table = formatting .Table (columns .columns )
9092 table .sortby = sortby
91- for guest in guests :
92- table .add_row ([value or formatting .blank ()
93- for value in columns .row (guest )])
93+ if not hardware or all_guests :
94+ for guest in guests :
95+ table .add_row ([value or formatting .blank ()
96+ for value in columns .row (guest )])
9497
95- env .fout (table )
98+ env .fout (table )
9699
97- hardware_guests = vsi .get_hardware_guests ()
98- for hardware in hardware_guests :
99- if hardware ['virtualHost' ]['guests' ]:
100- title = "Hardware(id = {hardwareId}) guests associated" .format (hardwareId = hardware ['id' ])
101- table_hardware_guest = formatting .Table (['id' , 'hostname' , 'CPU' , 'Memory' , 'Start Date' , 'Status' ,
102- 'powerState' ], title = title )
103- table_hardware_guest .sortby = 'hostname'
104- for guest in hardware ['virtualHost' ]['guests' ]:
105- table_hardware_guest .add_row ([
106- guest ['id' ],
107- guest ['hostname' ],
108- '%i %s' % (guest ['maxCpu' ], guest ['maxCpuUnits' ]),
109- guest ['maxMemory' ],
110- utils .clean_time (guest ['createDate' ]),
111- guest ['status' ]['keyName' ],
112- guest ['powerState' ]['keyName' ]
113- ])
114- env .fout (table_hardware_guest )
100+ if hardware or all_guests :
101+ hardware_guests = vsi .get_hardware_guests ()
102+ for hd_guest in hardware_guests :
103+ if hd_guest ['virtualHost' ]['guests' ]:
104+ title = "Hardware(id = {hardwareId}) guests associated" .format (hardwareId = hd_guest ['id' ])
105+ table_hardware_guest = formatting .Table (['id' , 'hostname' , 'CPU' , 'Memory' , 'Start Date' , 'Status' ,
106+ 'powerState' ], title = title )
107+ table_hardware_guest .sortby = 'hostname'
108+ for guest in hd_guest ['virtualHost' ]['guests' ]:
109+ table_hardware_guest .add_row ([
110+ guest ['id' ],
111+ guest ['hostname' ],
112+ '%i %s' % (guest ['maxCpu' ], guest ['maxCpuUnits' ]),
113+ guest ['maxMemory' ],
114+ utils .clean_time (guest ['createDate' ]),
115+ guest ['status' ]['keyName' ],
116+ guest ['powerState' ]['keyName' ]
117+ ])
118+ env .fout (table_hardware_guest )
0 commit comments