Ich habe versucht, die Instanz von Bluemix IaaS (ehemals SoftLayer) über die API abzubrechen.
Es wird davon ausgegangen, dass Sie die folgenden Artikel verstehen. Erfahren Sie mehr über die Bluemix Infrastructure-API (ehemals SoftLayer).
ShinobiLayer: SoftLayer-API Nächster Schritt: Datentyp Objekt (1) --Qiita
Ich habe ein Skript erstellt, mit dem BillingItemId in der letzten Spalte der detaillierten Geräteliste abgerufen werden kann. Verwenden Sie es daher.
getDevicesTable-BillID.py
import SoftLayer
import dateutil.parser
from prettytable import PrettyTable
# account info
client = SoftLayer.create_client_from_env()
objectmask_vitualGuests = """
id,
virtualGuests[
id,
billingItem[
id,
cancellationDate
],
notes,
provisionDate,
fullyQualifiedDomainName,
primaryBackendIpAddress,
primaryIpAddress,
datacenter[
longName
],
operatingSystem[
softwareLicense[
softwareDescription[
name
]
],
passwords[
username,
password
]
]
]
"""
objectmask_hardware = """
id,
hardware[
id,
billingItem[
id,
cancellationDate
],
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([
'ID',
'Device Name',
'Type',
'Location',
'Public IP',
'Private IP',
'Start Date',
'Cancel Date',
'OS Name',
'Username',
'Password',
'BillID'
])
for key in range(len(vg['virtualGuests'])):
for key2 in range(len(vg['virtualGuests'][key]['operatingSystem']['passwords'])):
table.add_row([
vg['virtualGuests'][key]['id'],
vg['virtualGuests'][key]['fullyQualifiedDomainName'],
"VSI",
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]['billingItem'].get('cancellationDate')[:16],
vg['virtualGuests'][key]['operatingSystem']['softwareLicense']['softwareDescription']['name'][:16],
vg['virtualGuests'][key]['operatingSystem']['passwords'][key2]['username'],
vg['virtualGuests'][key]['operatingSystem']['passwords'][key2].get('password'),
vg['virtualGuests'][key]['billingItem'].get('id')
])
for key in range(len(hw['hardware'])):
for key2 in range(len(hw['hardware'][key]['operatingSystem']['passwords'])):
table.add_row([
hw['hardware'][key]['id'],
hw['hardware'][key]['fullyQualifiedDomainName'],
"BMS",
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]['billingItem'].get('cancellationDate')[:16],
hw['hardware'][key]['operatingSystem']['softwareLicense']['softwareDescription']['name'][:16],
hw['hardware'][key]['operatingSystem']['passwords'][key2]['username'],
hw['hardware'][key]['operatingSystem']['passwords'][key2]['password'],
hw['hardware'][key]['billingItem'].get('id')
])
print(table)
#Ausführungsbefehl
python ../Devices/getDevicesTable.py
#Ergebnis
+----------+-----------------------------------------------+------+-------------+-----------------+----------------+------------+-------------+------------------+---------------+----------+-----------+
| ID | Device Name | Type | Location | Public IP | Private IP | Start Date | Cancel Date | OS Name | Username | Password | BillID |
+----------+-----------------------------------------------+------+-------------+-----------------+----------------+------------+-------------+------------------+---------------+----------+-----------+
| 22222222 | xxxxxxxxxxxxx.xxxxxxxxxxxxxxx01.vsphere.local | VSI | Tokyo 2 | xxx.xxx.xx.x | xx.xxx.xx.xx | 2016/xx/xx | | Windows 2012 R2 | xxxxxxxxxxxxx | xxxxxxxx | 111111111 |
Ich habe ein Skript erstellt, das durch Angabe von BillingItemId sofort / ABD abbrechen kann. Verwenden Sie es daher.
cancelItem.py
import SoftLayer
import json
import sys
parm=sys.argv
itemId=parm[1]
# menu
print (30 * '-')
print (" M A I N - M E N U")
print (30 * '-')
print ("1. Immediate Cancel")
print ("2. ABD Cancel")
print (30 * '-')
# account info
client = SoftLayer.create_client_from_env()
Billing = client['SoftLayer_Billing_Item']
# define option
is_valid=0
while not is_valid :
try :
choice = int ( raw_input('Enter your choice [1-2] : ') )
is_valid = 1 ## set it to 1 to validate input and to terminate the while..not loop
except ValueError, e :
print ("'%s' is not a valid integer." % e.args[0].split(": ")[1])
### Take action as per selected menu-option ###
if choice == 1:
print ("Cancelling Immediately...")
cancel = Billing.cancelItem(True,False,"No longer needed",id=itemId)
print('Completed!')
elif choice == 2:
print ("Configuring ABD Cancellation...")
cancel = Billing.cancelItem(False,False,"No longer needed",id=itemId)
print('Completed!')
else:
print ("Invalid number. Try again...")
#Ausführungsbefehl
python cancelItem.py 111111111
#Ergebnis
------------------------------
M A I N - M E N U
------------------------------
1. Immediate Cancel
2. ABD Cancel
------------------------------
Enter your choice [1-2] : 1
Cancelling Immediately...
Completed!
Recommended Posts