2016-04-22 24 views
1

SoftLayer Python API VSManagerを使用して再起動するか、power-off/on仮想マシンインスタンスを使用する場所がわかりません。Softlayer Python APIを使用して仮想マシンを再起動する方法

操作がでXMLRPC APIで説明されています

http://developer.softlayer.com/reference/services/SoftLayer_Virtual_Guest

が、私は、同等で見つけることができません。

http://softlayer-python.readthedocs.org/en/latest/api/managers/vs.html

答えて

3

実際マネージャーは、あなたがここにそのためのAPI呼び出しいくつかの例をしなければならないという実装を持っていません。

""" 
Power off Guest 

The scripts will look for a VSI which has an specific 
hostname and the it powers off the VSI by making a single call 
to the SoftLayer_Virtual_Guest::powerOff method. 

Important manual pages: 
http://sldn.softlayer.com/reference/services/SoftLayer_Acount/ 
http://sldn.softlayer.com/reference/services/SoftLayer_Acount/getVirtualGuests 
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/setTags 

License: http://sldn.softlayer.com/article/License 
Author: SoftLayer Technologies, Inc. <[email protected]> 
""" 
import SoftLayer 

""" 
# Your SoftLayer API username and key. 
# 
# Generate an API key at the SoftLayer Customer Portal: 
# https://manage.softlayer.com/Administrative/apiKeychain 
""" 
username = 'set me' 
key = 'set me' 

# The name of the machine you wish to power off 
virtualGuestName = 'rctest' 

# Declare a new API service object 
client = SoftLayer.Client(username=username, api_key=key) 


try: 
    # Getting all virtual guest that the account has: 
    virtualGuests = client['SoftLayer_Account'].getVirtualGuests() 
except SoftLayer.SoftLayerAPIError as e: 
    """ 
    If there was an error returned from the SoftLayer API then bomb out with the 
    error message. 
    """ 
    print("Unable to retrieve hardware. " 
      % (e.faultCode, e.faultString)) 

# Looking for the virtual guest 
virtualGuestId = '' 
for virtualGuest in virtualGuests: 
    if virtualGuest['hostname'] == virtualGuestName: 
     virtualGuestId = virtualGuest['id'] 

try: 
    # Power off the virtual guest 
    virtualMachines = client['SoftLayer_Virtual_Guest'].powerOff(id=virtualGuestId) 
    print ("powered off") 
except SoftLayer.SoftLayerAPIError as e: 
    """ 
    If there was an error returned from the SoftLayer API then bomb out with the 
    error message. 
    """ 
    print("Unable to power off the virtual guest" 
      % (e.faultCode, e.faultString)) 

-

""" 
Reboot Virtual Guest. 
It reboots a SoftLayer Virtual Guest 


Important manual pages: 
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/rebootDefault 

License: http://sldn.softlayer.com/article/License 
Author: SoftLayer Technologies, Inc. <[email protected]> 
""" 
# So we can talk to the SoftLayer API: 
import SoftLayer 

# From pprint import pprint as pp 
# For nice debug output 
from pprint import pprint as pp 

# Your SoftLayer API username and key. 
API_USERNAME = 'set me' 
API_KEY = 'set me' 

# If you don't know your server id you can call getVirtualGuests() in the 
# SoftLayer_Account API service to get a list of Virtual Guests 
serverId = 10403817 

# Create a connection to API service. 
client = SoftLayer.Client(
     username=API_USERNAME, 
     api_key=API_KEY 
) 

# Reboot the Virtual Guest 
try: 

    result = client['Virtual_Guest'].rebootDefault(id=serverId) 
    pp(result) 

except SoftLayer.SoftLayerAPIError as e: 
     pp('Unable to reboot the server faultCode=%s, faultString=%s' 
      % (e.faultCode, e.faultString)) 

よろしく

関連する問題