常田です。
さて、今日も引き続きAPIを見て行きたいと思います。
まだ難しいことは出来ないので少しづつ調べていきたいと思います。
(SoftLayerのAPIもPythonも初心者のため誤りがあればご指摘いただければ幸いです)
ディスク情報の取得
slcliコマンドを利用して vs detail をみてもディスクが見えないですね。各サーバに付いているストレージがいくつなのかわかると便利なのでその辺りを見て行きたいと思います。
サーバのIDを取得
なにはなくともサーバのIDが必要です。
>>> pp.pprint(client['Account'].getVirtualGuests(mask='id,hostname'))
[ { 'hostname': 'xxxx', 'id': 7704906},
{ 'hostname': 'xxxx', 'id': 8008308},
{ 'hostname': 'xxxx', 'id': 8436747}]
各サーバのディスク情報を取得します。
バックアップを取得しようとしたりするとわかるのですが仮想サーバは実はSWAP領域を別に所有しています。このSWAP領域はDisk1(2本目)として構成されています。
maskにRelational先のdiskImageを指定していました。これにより、各ディスクの容量(capacity)を取得することが出来るようになりました。
>>> pp.pprint(client['Virtual_Guest'].getBlockDevices(id=8436747,mask='diskImage'))
[ { 'bootableFlag': 1,
'createDate': '2015-03-12T10:56:10-06:00',
'device': '0',
'diskImage': { 'capacity': 25,
'createDate': '2015-03-12T10:55:35-06:00',
'description': 'splunk.sl.com',
'id': 7335393,
'modifyDate': '',
'name': 'splunk.sl.com',
'parentId': '',
'storageRepositoryId': 2452057,
'typeId': 241,
'units': 'GB',
'uuid': '224d054b-4dd2-4f18-b2f8-cb43d0777a28'},
'diskImageId': 7335393,
'guestId': 8436747,
'hotPlugFlag': 0,
'id': 11380253,
'modifyDate': '',
'mountMode': 'RW',
'mountType': 'Disk',
'statusId': 1,
'uuid': 'd8a11094-35fd-bc5e-e489-a6860e1f5aad'},
{ 'bootableFlag': 0,
'createDate': '2015-03-12T10:55:48-06:00',
'device': '1',
'diskImage': { 'capacity': 2,
'createDate': '2015-03-12T10:55:43-06:00',
'description': '8436747-SWAP',
'id': 7335397,
'modifyDate': '',
'name': '8436747-SWAP',
'parentId': '',
'storageRepositoryId': 2257918,
'typeId': 246,
'units': 'GB',
'uuid': '94c5d650-033d-4129-a299-22bf467ff124'},
'diskImageId': 7335397,
'guestId': 8436747,
'hotPlugFlag': 0,
'id': 11380235,
'modifyDate': '',
'mountMode': 'RW',
'mountType': 'Disk',
'statusId': 1,
'uuid': '983081a7-6a8b-0b85-8e49-ed81d94c9cd2'},
{ 'bootableFlag': 0,
'createDate': '2015-03-12T10:55:56-06:00',
'device': '2',
'diskImage': { 'capacity': 1000,
'createDate': '2015-03-12T10:55:55-06:00',
'description': 'Disk 2',
'id': 7335405,
'modifyDate': '',
'name': 'Disk 2',
'parentId': '',
'storageRepositoryId': 2452059,
'typeId': 241,
'units': 'GB',
'uuid': '5ac1ff49-8eb3-4eed-8090-9a38ed49bfe2'},
'diskImageId': 7335405,
'guestId': 8436747,
'hotPlugFlag': 0,
'id': 11380251,
'modifyDate': '',
'mountMode': 'RW',
'mountType': 'Disk',
'statusId': 1,
'uuid': '4db99fa7-aba4-94c8-dc89-d3a9f4dabedc'}]
ディスクの詳細を見る
SoftLayer_Virtual_Disk_Imageを調べていくとさらに見ることが出来ます。すでに先ほどの例の場合にはRelationalで呼び出していますが単独で調べる場合には diskImageId をidに調べて行けば良いと思います。
サンプル
Qiita等で書かれているSoftLayerのサンプルソースを参考にして同じようになるように書いてみました。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from prettytable import PrettyTable
import SoftLayer
import sys
client = SoftLayer.Client()
_maskVirtualGuest = '''
id,
fullyQualifiedDomainName
'''
_tableHeader = [
'id',
'fdqn',
'device0',
'device1',
'device2',
'device3',
'device4',
'device5'
]
instances = client['Account'].getVirtualGuests(mask=_maskVirtualGuest)
table = PrettyTable(_tableHeader)
table.padding_width = 1
for inst in instances:
diskImageIds = client['Virtual_Guest'].getBlockDevices(id=inst['id'],mask='diskImageId')
count = 0
storage = {}
for disk in diskImageIds:
if disk.get('diskImageId'):
diskImages = client['Virtual_Disk_Image'].getObject(id=disk['diskImageId'],mask='capacity,units')
storage[count] = diskImages['capacity']
count = count + 1
table.add_row(
[
inst['id'],
inst['fullyQualifiedDomainName'],
storage.get(0,'-'),
storage.get(1,'-'),
storage.get(2,'-'),
storage.get(3,'-'),
storage.get(4,'-'),
storage.get(5,'-'),
]
)
print(table)
print("instances")
exit()
実行すると以下のようにストレージの容量が取得できます。
+---------+---------------------+----------+----------+----------+----------+----------+----------+
| id | fdqn | device 0 | device 1 | device 2 | device 3 | device 4 | device 5 |
+---------+---------------------+----------+----------+----------+----------+----------+----------+
| 7704906 | xxx.nic30.info | 25 | 2 | - | - | - | - |
| 8008308 | xxxx.sl.com | 25 | 2 | - | - | - | - |
| 8436747 | xxxx.sl.com | 25 | 2 | 1000 | - | - | - |
+---------+---------------------+----------+----------+----------+----------+----------+----------+
(instances)
まとめ
ストレージとしてはこれ以外にもSANなのかLocalなのかという情報もあると良いかもしれません。