0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Bluemix-Infra(SoftLayer)のデバイスのユーザー名とパスワードを一覧表示するスクリプト

Posted at

#内容
Bluemix Infrastructure (旧SoftLayer)のデバイス(ベアメタルや仮想サーバー)のユーザー名とパスワードを、毎回ポータルにアクセスするのも煩わしくなってきたので、コマンドで一覧表示できるスクリプトをつくりました。

#参考記事
ShinobiLayer: Virtual Serverの作成者や稼動ホストのRack/Slot情報を確認するスクリプト - Qiita

#スクリプト

getDevicesTable.py
import SoftLayer
import dateutil.parser
from prettytable import PrettyTable

# account info
client = SoftLayer.create_client_from_env()

objectmask_vitualGuests = """
	id,
	virtualGuests[
		id,
		notes,
		provisionDate,
		fullyQualifiedDomainName,
		primaryBackendIpAddress,
		primaryIpAddress,
		datacenter[
			longName
		],
		operatingSystem[
                        softwareLicense[
                                softwareDescription[
                                        name
                                ]
                        ],
                        passwords[
                                username,
                                password
                        ]
                ]
	]
"""

objectmask_hardware = """
	id,
	hardware[
		id,
		notes,
		provisionDate,
		fullyQualifiedDomainName,
		primaryBackendIpAddress,
		primaryIpAddress,
		datacenter[
			longName
		],
		operatingSystem[
			softwareLicense[
				softwareDescription[
					name
				]
			],
			passwords[		
				username,
				password
			]
		]
	]
"""

vg = client['Account'].getObject(mask=objectmask_vitualGuests)
hw = client['Account'].getObject(mask=objectmask_hardware)

virtualGuests=vg.keys()[0]
hardware=hw.keys()[0]

table = PrettyTable([
	'Device Name',
	'Device Type',
	'Location',
	'Public IP',
	'Private IP',
	'Start Date',
	'OS Name',
	'Username',
	'Password'])

for key in range(len(vg['virtualGuests'])):
	for key2 in range(len(vg['virtualGuests'][key]['operatingSystem']['passwords'])):
		table.add_row([
			vg['virtualGuests'][key]['fullyQualifiedDomainName'],
                	virtualGuests,
			vg['virtualGuests'][key]['datacenter']['longName'],
			vg['virtualGuests'][key].get('primaryIpAddress'),
			vg['virtualGuests'][key]['primaryBackendIpAddress'],
			dateutil.parser.parse(vg['virtualGuests'][key]['provisionDate']).strftime('%Y/%m/%d'),
			vg['virtualGuests'][key]['operatingSystem']['softwareLicense']['softwareDescription']['name'][:16],
			vg['virtualGuests'][key]['operatingSystem']['passwords'][key2]['username'],
			vg['virtualGuests'][key]['operatingSystem']['passwords'][key2]['password']
		])
for key in range(len(hw['hardware'])):
	for key2 in range(len(hw['hardware'][key]['operatingSystem']['passwords'])):
	        table.add_row([
        	        hw['hardware'][key]['fullyQualifiedDomainName'],
        	        hardware,
        	        hw['hardware'][key]['datacenter']['longName'],
			hw['hardware'][key].get('primaryIpAddress'),
        	        hw['hardware'][key]['primaryBackendIpAddress'],
        	        dateutil.parser.parse(hw['hardware'][key]['provisionDate']).strftime('%Y/%m/%d'),
			hw['hardware'][key]['operatingSystem']['softwareLicense']['softwareDescription']['name'][:16],
			hw['hardware'][key]['operatingSystem']['passwords'][key2]['username'],
			hw['hardware'][key]['operatingSystem']['passwords'][key2]['password']
        	])

print(table)

#実行結果の例

+-----------------------------------------------+---------------+----------+-----------------+---------------+------------+------------------+-----------------------------+---------------+
|                  Device Name                  |  Device Type  | Location |    Public IP    |   Private IP  | Start Date |     OS Name      |           Username          |    Password   |
+-----------------------------------------------+---------------+----------+-----------------+---------------+------------+------------------+-----------------------------+---------------+
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.vsphere.local | virtualGuests | Tokyo 2  |       None      | 10.133.xx.xxx | 2016/10/26 | Windows 2012 R2  |        Administrator        |    xxxxxxxx   |
|            win2012r2.softlayer.com            | virtualGuests | Tokyo 2  |  161.202.xxx.xx | 10.132.xx.xxx | 2016/05/09 | Windows 2012 R2  |        Administrator        |    xxxxxxxx   |
|              esx01.softlayer.com              |    hardware   | Tokyo 2  |  161.202.xxx.xx | 10.132.xx.xxx | 2016/04/19 | Customer Install |             root            |   xxxxxxxxx   |
|              esx02.softlayer.com              |    hardware   | Tokyo 2  |  161.202.xxx.xx | 10.132.xx.xxx | 2016/04/19 | Customer Install |             root            | xxxxxxxxxxxxx |
|             vyatta01.softlayer.com            |    hardware   | Tokyo 2  | 161.202.xxx.xxx | 10.132.xx.xxx | 2016/04/08 | Vyatta Subscript |             root            |    xxxxxxxx   |
|             vyatta01.softlayer.com            |    hardware   | Tokyo 2  | 161.202.xxx.xxx | 10.132.xx.xxx | 2016/04/08 | Vyatta Subscript |            vyatta           |    xxxxxxxx   |
+-----------------------------------------------+---------------+----------+-----------------+---------------+------------+------------------+-----------------------------+---------------+
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?