2016-11-12 3 views
0

Suchen Sie nach Hilfe zu starten slcli verwenden, um Befehle für Softlayer-Maschinen für Herunterfahren, Starten und Neustart vms auszuführen. Ich installierte das Paket unter Ubuntu 14.04 sudo apt-get installieren python-softlayer, jetzt versuchen, slcli-Setup-Befehl ausführen, aber mit der Suche nach, wo es ausgeführt wird, ist es nicht im Pfad auf der Bash-Shell, noch in Python nach ich SoftLayer importieren, was fehlt mir, um weiter zu kommen?Wie installiere ich slcli Softlayer api

Antwort

0

Sie können den Befehl slcli config setup von überall ausführen, sofern das Paket ordnungsgemäß installiert wurde. Ich empfehle generell, pip zu verwenden, um das SoftLayer-Paket zu installieren.

sudo apt-get purge python-softlayer 

sudo apt-get install python-setuptools python-pip 

sudo pip install softlayer 
0

Stellen Sie sicher, Python und pip korrekt installiert sind, dann laufen:

sudo apt-get install python-softlayer

Dennoch, wenn diese Arbeiten nicht, dann versuchen pip Installation mit:

sudo pip install softlayer 

Sobald slcli ist korrekt installiert läuft slcli ohne Argumente sollte das Optionsmenü anzeigen, wo Sie zusätzliche Informationen miterhalten können

Verwenden Sie slcli setup, um Ihre Standardwerte festzulegen, und slcli config show, um es anzuzeigen.

Um vs mit slcli verwenden, um diese Befehle zu verwalten:

slcli vs list 
slcli vs power-on 1234567 
slcli vs power-off 1234567 
slcli vs reboot 1234567 

würde die virtuelle Gast-ID seine slcli vs list erhielt unter Verwendung von

Es ist auch möglich, die oben mit einem Standard-Python-Skript zu erreichen , hier einige Beispiele:

""" 
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)) 

Zum Neustart

""" 
    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)) 
Verwandte Themen