J'ai essayé d'annuler l'instance de Bluemix IaaS (anciennement SoftLayer) via l'API.
Il est supposé que vous comprenez les articles suivants. En savoir plus sur l'API Bluemix Infrastructure (anciennement SoftLayer).
ShinobiLayer: API SoftLayer Étape suivante: objet de type de données (1) --Qiita
J'ai créé un script qui peut obtenir BillingItemId dans la dernière colonne de la liste détaillée des appareils, veuillez donc l'utiliser.
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)
#Commande d'exécution
python ../Devices/getDevicesTable.py 
#résultat
+----------+-----------------------------------------------+------+-------------+-----------------+----------------+------------+-------------+------------------+---------------+----------+-----------+
|    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 |
J'ai créé un script qui peut annuler Immédiatement / ABD en spécifiant BillingItemId, veuillez donc l'utiliser.
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...")
#Commande d'exécution
python cancelItem.py 111111111
#résultat
------------------------------
   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