2017-10-23 2 views
0

Ich verwende Python-API, um Vsi zu erstellen, und bekam ein Problem, wenn ich versuchte, ein Vsi aus einer vorhandenen Bildvorlage zu erstellen. Meine Python-Version ist 3.6.3 und ich betreibe meine Python-Skripte auf Windows 7.Problem beim Erstellen eines Vsi aus einer Bildvorlage

Ihre Dokumentation (http://softlayer-python.readthedocs.io/en/latest/api/managers/vs.html) sagt:

os_code (string) – The operating system to use. Cannot be specified if image_id is specified.

image_id (int) – The ID of the image to load onto the server. Cannot be specified if os_code is specified.

Als ich image_id ohne os_code in meinem Python-Skript angeben, bekam ich die folgende Fehler:

Traceback (most recent call last): 
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\transports.py", line 173, in __call__ 
result = utils.xmlrpc_client.loads(resp.content)[0][0] 
File "c:\users\ods\appdata\local\programs\python\python36\Lib\xmlrpc\client.py", line 1021, in loads 
return u.close(), u.getmethodname() 
File "c:\users\ods\appdata\local\programs\python\python36\Lib\xmlrpc\client.py", line 656, in close 
raise Fault(**self._stack[0]) 
xmlrpc.client.Fault: <Fault SoftLayer_Exception_MissingCreationProperty: "The property 'operatingSystemReferenceCode' must be set to create an instance of 'SoftLayer_Virtual_Guest'."> 

Während der oben genannten Ausnahmebehandlung erfolgt eine weitere Ausnahme:

Traceback (most recent call last): 
File "C:\Users\ods\Documents\slenv\", line 66, in <module> 
create_vsi() 
File "C:\Users\ods\Documents\slenv\", line 50, in create_vsi 
ssh_keys=ssh_keys) 
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\managers\vs.py", line 514, in verify_create_instance 
return self.guest.generateOrderTemplate(create_options) 
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\API.py", line 392, in call_handler 
return self(name, *args, **kwargs) 
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\API.py", line 360, in call 
return self.client.call(self.name, name, *args, **kwargs) 
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\API.py", line 263, in call 
return self.transport(request) 
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\transports.py", line 195, in __call__ 
raise _ex(ex.faultCode, ex.faultString) 
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_MissingCreationProperty): The property 'operatingSystemReferenceCode' must be set to create an instance of 'SoftLayer_Virtual_Guest'. 

Also habe ich mein Skript geändert, um sowohl os_code als auch image_id anzugeben, dann kann ich erfolgreich ein vsi erstellen, aber die Image-Vorlage wird nicht in das vsi geladen.

Können Sie bitte dabei helfen? Vielen Dank.

Antwort

0

es ein Problem in der Dokumentation, ist die image_id kein INT Art. Die Methode create_instance ruft die Methode Softlayer_Virtual_Guest::createObject auf. Bei dieser Methode wird die globale ID des Bildes anstelle der ID verwendet.

die globale Kennung Um zu wissen, Sie SLCLI oder die Methode get_image hier beschriebenen http://softlayer-python.readthedocs.io/en/latest/api/managers/image.html

mgr = ImageManager(client) 
resp = mgr.get_image(image_id=1211529) 

Sie können es testen, indem Sie mit folgenden Python-Code, ändern Sie die Werte in den Optionen Variable mit Ihren eigenen Daten verwenden können, .

import SoftLayer 
from SoftLayer import VSManager 
from pprint import pprint as pp 

USERNAME = 'set me' 
API_KEY = 'set me' 

options = { 
    'cpus': 4, 
    'datacenter': 'tor01', 
    'domain': 'softlayer.xyz', 
    'hostname': 'hostname-test', 
    'dedicated': False, 
    'hourly': True, 
    'local_disk': False, 
    'memory': 65536, 
    'nic_speed': 1000,  
    'image_id': '87be78f2-fa03-4250-840e-bfa66d14866c', 
    'private_vlan': 12315455, 
    'private': False  
} 

# Creating client instance 
client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY) 

# Get the Hardware Manager 
vsi_mgr = VSManager(client) 

try: 
    # verify_create_instance() will check for errors 
    # Change the method by create_instance(**options) when you ready to order. 
    resp = vsi_mgr.verify_create_instance(**options) 

    # Print retrieved value 
    pp(resp) 
except SoftLayer.SoftLayerAPIError as e: 
    """ 
    If there was an error returned from the SoftLayer API then bomb out with 
    the error message. 
    """ 
    pp("Unable to create Virtual Instance: %s, %s " % (e.faultCode, e.faultString)) 
+0

Get image_id zuerst aus der Ausgabe von ‚slcli Bildliste‘, dann bekommt seine globale ID aus der Ausgabe von ‚slcli Bild Detail ‘ – Muo

0

Zu Ihrer Information unten ist der Python-Skript, das ich ein vsi erstellen verwenden, um tatsächlich oder nur versuchen, einen Testlauf:

from __future__ import print_function 
import SoftLayer 
from SoftLayer.managers.vs import VSManager 

def create_vsi(): 
    #Create a client to the SoftLayer_Account API service. 
    #Note: currently set without the user ID and API key since 
    #it will by default use the values set in the CLI 
    #to use other values use SoftLayer.Client(sl_username, sl_api_key) 
    client = SoftLayer.create_client_from_env(username="your username", 
    api_key="your key") 
    vsi_mgr = VSManager(client) 

    # uncomment to display create options 
    #print(vsi_mgr.get_create_options()) 

    # common values 
    datacenter = 'tor01' # the data center code 
    cpus = 4 
    memory = 65536   # MB 
    os_code = 'REDHAT_7_64' # the operating system code. Doesn't need this as we'll use image_id 
    local_disk = False # local disk or SAN 
    hourly = True # hourly or monthly billing 
    dedicated = False # multi-tenant or single tenant 
    image_id = '1211529' # slcli image list 
    nic_speed = 1000 # speed of network device 
    disks = [100] # size of the disks - GB 
    private = False # private networking only or include public internet networking as well. When set to true, Public IP will not be available. 

    #ssh_keys = [227113, 229467] # the IDs of the ssh keys to load on the server - use slcli sshkey list 
    ssh_keys = [504233]    # Audrey's SSH Key 

    # server properties 
    hostname = 'testapi' 
    domain = 'smartworks.com' # the domain name suffix for the host 
    private_vlan = '1219977' # VLAN for the server see VLAN list above - use slcli vlan list 
    #tags = 'owner:bob,project:poc,type:docker' 

    # code that can verify the create operation without actually doing it 
    template = vsi_mgr.verify_create_instance(hostname=hostname, domain=domain, 
    # os_code=os_code, 
     cpus=cpus, memory=memory, datacenter=datacenter, 
     image=image_id, local_disk=local_disk, 
     hourly=hourly, dedicated=dedicated, 
     private_vlan=private_vlan, disks=disks, 
     nic_speed=nic_speed, private=private, 
     ssh_keys=ssh_keys) 

    print(template) 

    # Code that will actually create the instance 
    # result = vsi_mgr.create_instance(hostname=hostname, domain=domain, os_code=os_code, 
     # cpus=cpus, memory=memory, datacenter=datacenter, 
     # image=image_id, local_disk=local_disk, 
     # hourly=hourly, dedicated=dedicated, 
     # private_vlan=private_vlan, disks=disks, 
     # nic_speed=nic_speed, private=private, 
     # ssh_keys=ssh_keys) 

    # print(result) 

if __name__ == '__main__': 
    create_vsi() 
Verwandte Themen