-
Notifications
You must be signed in to change notification settings - Fork 194
Description
Please triple-check to make sure that you have properly masked out user credentials like usernames, passwords and API keys before submitting your issue
Expected Behavior
createObjects with the RestTransport should operate the same way as the XmlRpcTransport. Calling createObjects with multiple objects should create each object, and return all created objects
Actual Behavior
Here is a script that I wrote to attempt creating multiple VSIs as the comments in the VS manager's create_instances function instructs. The endpoint I was pointing to was endpoint_url = https://api.softlayer.com/rest/v3.1/
import os
import SoftLayer
config_file = os.path.expanduser('~/.softlayer')
client = SoftLayer.create_client_from_env(config_file=config_file)
vs = SoftLayer.VSManager(client)
new_vsi = {
'domain': 'sl.test',
'hostname': 'sl-test',
'datacenter': 'dal13',
'cpus': 1,
'os_code' : 'UBUNTU_LATEST',
'hourly': True,
'disks': ('100',),
'local_disk': True,
'memory': 1024
}
instances = [new_vsi.copy(), new_vsi.copy()]
instances[0]['hostname'] = 'sl-test0'
instances[1]['hostname'] = 'sl-test1'
vsis = vs.create_instances(instances)
for vsi in vsis:
print vsi
The error output was:
Traceback (most recent call last):
File "test_createObjects.py", line 26, in <module>
vsis = vs.create_instances(instances)
File "/Users/rlrossit/venv/lib/python2.7/site-packages/SoftLayer/managers/vs.py", line 635, in create_instances
for kwargs in config_list])
File "/Users/rlrossit/venv/lib/python2.7/site-packages/SoftLayer/API.py", line 392, in call_handler
return self(name, *args, **kwargs)
File "/Users/rlrossit/venv/lib/python2.7/site-packages/SoftLayer/API.py", line 360, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/Users/rlrossit/venv/lib/python2.7/site-packages/SoftLayer/API.py", line 263, in call
return self.transport(request)
File "/Users/rlrossit/venv/lib/python2.7/site-packages/SoftLayer/transports.py", line 315, in __call__
message)
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(500): The property 'hostname' must be set to create an instance of 'SoftLayer_Virtual_Guest'.
The hostname on each instance is set, so this isn't the actual error that's happening. This is also happening for security groups createObjects, and what's happening with security groups is it is just doing a create of one security group with no attributes set on it.
For security groups, we attempted to make the REST call using curl:
curl --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" -k -X POST 'https://api.softlayer.com/rest/v3/SoftLayer_Network_SecurityGroup' -d '{"parameters": [{"name": "some name1","description":"some description"},{"name": "some name2","description":"some description"}]}'
This only created one security group instead of both. The call, in order to make it work, was:
curl -s --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" -k -X POST 'https://api.softlayer.com/rest/v3/SoftLayer_Network_SecurityGroup/createObjects' -d '{"parameters": [[{"name": "some name1","description":"some description"},{"name": "some name2","description":"some description"}]]}'
The solution was to call createObjects directly, where softlayer-python is just calling https://api.softlayer.com/rest/v3/SoftLayer_Network_SecurityGroup with POST. This probably means that if a "special method" (https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/transports.py#L32-L38) is encountered, we should change it to POST, but we shouldn't remove the method name in case it is the plural API that is being called.
Environment Information
Operating System: Mac OS 10.12.6
softlayer-python version (slcli --version): slcli (SoftLayer Command-line), version 5.2.14