#NEWLINE# @ click . command ( ) #NEWLINE# @ click . argument ( 'identifier' ) #NEWLINE# @ click . option ( '--passwords' , is_flag = True , help = 'Show passwords (check over your shoulder!)' ) #NEWLINE# @ click . option ( '--price' , is_flag = True , help = 'Show associated prices' ) #NEWLINE# @ environment . pass_env #NEWLINE# def cli( env , identifier , passwords = False , price = False ) : #NEWLINE# #INDENT# 'Get details for a virtual server.' #NEWLINE# vsi = SoftLayer . VSManager ( env . client ) #NEWLINE# table = formatting . KeyValueTable ( [ 'name' , 'value' ] ) #NEWLINE# table . align [ 'name' ] = 'r' #NEWLINE# table . align [ 'value' ] = 'l' #NEWLINE# vs_id = helpers . resolve_id ( vsi . resolve_ids , identifier , 'VS' ) #NEWLINE# result = vsi . get_instance ( vs_id ) #NEWLINE# result = utils . NestedDict ( result ) #NEWLINE# table . add_row ( [ 'id' , result [ 'id' ] ] ) #NEWLINE# table . add_row ( [ 'guid' , result [ 'globalIdentifier' ] ] ) #NEWLINE# table . add_row ( [ 'hostname' , result [ 'hostname' ] ] ) #NEWLINE# table . add_row ( [ 'domain' , result [ 'domain' ] ] ) #NEWLINE# table . add_row ( [ 'fqdn' , result [ 'fullyQualifiedDomainName' ] ] ) #NEWLINE# table . add_row ( [ 'status' , formatting . FormattedItem ( ( result [ 'status' ] [ 'keyName' ] or formatting . blank ( ) ) , ( result [ 'status' ] [ 'name' ] or formatting . blank ( ) ) ) ] ) #NEWLINE# table . add_row ( [ 'state' , formatting . FormattedItem ( utils . lookup ( result , 'powerState' , 'keyName' ) , utils . lookup ( result , 'powerState' , 'name' ) ) ] ) #NEWLINE# table . add_row ( [ 'active_transaction' , formatting . active_txn ( result ) ] ) #NEWLINE# table . add_row ( [ 'datacenter' , ( result [ 'datacenter' ] [ 'name' ] or formatting . blank ( ) ) ] ) #NEWLINE# operating_system = ( utils . lookup ( result , 'operatingSystem' , 'softwareLicense' , 'softwareDescription' ) or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# table . add_row ( [ 'os' , formatting . FormattedItem ( ( operating_system . get ( 'version' ) or formatting . blank ( ) ) , ( operating_system . get ( 'name' ) or formatting . blank ( ) ) ) ] ) #NEWLINE# table . add_row ( [ 'os_version' , ( operating_system . get ( 'version' ) or formatting . blank ( ) ) ] ) #NEWLINE# table . add_row ( [ 'cores' , result [ 'maxCpu' ] ] ) #NEWLINE# table . add_row ( [ 'memory' , formatting . mb_to_gb ( result [ 'maxMemory' ] ) ] ) #NEWLINE# table . add_row ( [ 'public_ip' , ( result [ 'primaryIpAddress' ] or formatting . blank ( ) ) ] ) #NEWLINE# table . add_row ( [ 'private_ip' , ( result [ 'primaryBackendIpAddress' ] or formatting . blank ( ) ) ] ) #NEWLINE# table . add_row ( [ 'private_only' , result [ 'privateNetworkOnlyFlag' ] ] ) #NEWLINE# table . add_row ( [ 'private_cpu' , result [ 'dedicatedAccountHostOnlyFlag' ] ] ) #NEWLINE# table . add_row ( [ 'created' , result [ 'createDate' ] ] ) #NEWLINE# table . add_row ( [ 'modified' , result [ 'modifyDate' ] ] ) #NEWLINE# if ( utils . lookup ( result , 'billingItem' ) != [ ] ) : #NEWLINE# #INDENT# table . add_row ( [ 'owner' , formatting . FormattedItem ( ( utils . lookup ( result , 'billingItem' , 'orderItem' , 'order' , 'userRecord' , 'username' ) or formatting . blank ( ) ) ) ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# table . add_row ( [ 'owner' , formatting . blank ( ) ] ) #NEWLINE# #UNINDENT# vlan_table = formatting . Table ( [ 'type' , 'number' , 'id' ] ) #NEWLINE# for vlan in result [ 'networkVlans' ] : #NEWLINE# #INDENT# vlan_table . add_row ( [ vlan [ 'networkSpace' ] , vlan [ 'vlanNumber' ] , vlan [ 'id' ] ] ) #NEWLINE# #UNINDENT# table . add_row ( [ 'vlans' , vlan_table ] ) #NEWLINE# if result . get ( 'notes' ) : #NEWLINE# #INDENT# table . add_row ( [ 'notes' , result [ 'notes' ] ] ) #NEWLINE# #UNINDENT# if price : #NEWLINE# #INDENT# table . add_row ( [ 'price rate' , result [ 'billingItem' ] [ 'recurringFee' ] ] ) #NEWLINE# #UNINDENT# if passwords : #NEWLINE# #INDENT# pass_table = formatting . Table ( [ 'software' , 'username' , 'password' ] ) #NEWLINE# for component in result [ 'softwareComponents' ] : #NEWLINE# #INDENT# for item in component [ 'passwords' ] : #NEWLINE# #INDENT# pass_table . add_row ( [ utils . lookup ( item , 'softwareLicense' , 'softwareDescription' , 'name' ) , item [ 'username' ] , item [ 'password' ] ] ) #NEWLINE# #UNINDENT# #UNINDENT# table . add_row ( [ 'users' , pass_table ] ) #NEWLINE# #UNINDENT# table . add_row ( [ 'tags' , formatting . tags ( result [ 'tagReferences' ] ) ] ) #NEWLINE# try : #NEWLINE# #INDENT# if ( not result [ 'privateNetworkOnlyFlag' ] ) : #NEWLINE# #INDENT# ptr_domains = env . client . call ( 'Virtual_Guest' , 'getReverseDomainRecords' , id = vs_id ) #NEWLINE# for ptr_domain in ptr_domains : #NEWLINE# #INDENT# for ptr in ptr_domain [ 'resourceRecords' ] : #NEWLINE# #INDENT# table . add_row ( [ 'ptr' , ptr [ 'data' ] ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except SoftLayer . SoftLayerAPIError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# env . fout ( table )