Reputation: 1354
I'm tyring to create a cluster in the same newtork, borh private and public, but I can't I tried through ansible, but it didn't worked Now I'm trying with the following python code
import SoftLayer
import time
client = SoftLayer.create_client_from_env(username='username',
api_key='key')
cpus = 8
ssh_keys = 682641
memory = 16384
mgr = SoftLayer.VSManager(client)
for id in range(1, 4):
host = u'dnode-%d' % (id)
tag = u'slave'
nodes = {
'domain': u'domain',
'hostname': host,
'datacenter': u'dal09',
'dedicated': False,
'private': False,
'cpus': cpus,
'os_code' : u'CENTOS_LATEST',
'hourly': True,
'ssh_keys': [ssh_keys],
# 'disks': ('25'),
'local_disk': True,
'memory': memory,
'tags': (tag)
}
vsi = mgr.create_instance(**nodes)
print vsi
time.sleep(10)# this is to avoid instantiation errorÇ:
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_Public): As an active participant of the Technology Incubator Program, you may only place one order at a time. Currently you have a pending order that needs final disposition before you can place another order.
This worked sometimes, but not always. I've tried to use public_vlan and private_vlan attributes but when I do it the servers didn't get instantiated.
UPDATE after Nelson answer. Ok so I'll have to change my python code to get the network from the first created workstation, and set it in the following servers from the cluster. What happen if there are no available network ips, for the amount of servers that I need to instantiate? Is there a way to determine in which network is better to instantiate my cluster? Is there a service for listing the available networks?
Upvotes: 0
Views: 152
Reputation: 2757
Regarding to you question "Is there a service for listing the available networks?". Try this script, it will help to get free slots (Free Ip Addresses) in the vlans from your account:
"""
This script retrieves the Total Ip Addresses, Usable Ip Address Count and Free Slots
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkVlans
http://sldn.softlayer.com/article/object-masks
http://sldn.softlayer.com/article/object-filters
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <[email protected]>
"""
import SoftLayer
from prettytable import PrettyTable
# Declare your SoftLayer username and apiKey
username = 'set me'
apikey = 'set me'
# Contact To SoftLayer
client = SoftLayer.Client(username=username, api_key=apikey)
# Declare an Object Mask to get additional information
object_mask = 'mask[primaryRouter,primarySubnet[datacenter[name]],subnets[billingItem, subnetType,networkIdentifier, cidr, totalIpAddresses, usableIpAddressCount, ipAddresses[ipAddress, isReserved, virtualGuest, hardware]]]'
result = client['SoftLayer_Account'].getNetworkVlans(mask=object_mask)
x = PrettyTable(["Vlan Id", "Vlan Number", "Subnet", "Total Ip Addresses", "Usable Ip Address Count","Free Slots"])
count = 0
for vlan in result:
for subnet in vlan['subnets']:
for item in subnet['ipAddresses']:
if item['isReserved'] == True:
count = count + 1
if 'hardware' in item:
count = count + 1
if 'virtualGuest' in item:
count = count + 1
if (int(subnet['usableIpAddressCount']) - count) > 0:
if subnet['subnetType'] == 'PRIMARY' or subnet['subnetType'] == 'ADDITIONAL_PRIMARY':
x.add_row([vlan['id'], str('%s %s' % (vlan['primaryRouter']['hostname'], vlan['vlanNumber'])), str('%s/%s' % (subnet['networkIdentifier'], subnet['cidr'])), subnet['totalIpAddresses'], subnet['usableIpAddressCount'], (int(subnet['usableIpAddressCount']) - count)])
count = 0
print(x)
Upvotes: 1
Reputation: 4386
If you want that your machines are in the same network you need to specify the VLAN for public and private network in your order otherwise there is no guarantie that they wil end up in the same network. see this example about orders:
https://softlayer.github.io/python/create_vsi_options/
If your servers are not being initiated, this likely is an issue with the softlayer provisioning proccess I recomend you to submit an ticket to softlayer and ask them why your server is not being initiated.
Regarding to your another error (the one related to one order at time), that is a restriction on your account, if you want to change it you need to talk with some softlayer's sales guy. You can fix your current code adding a wait until the order is complete and then make the next order, the softlayer Python APi has a method for that see:
https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/managers/vs.py#L393
you just need to add to your code something like this:
Example:: # Will return once vsi 12345 is ready, or after 10 checks ready = mgr.wait_for_ready(12345, 10)
the number "12345" is the ID of the server you just ordered, you can get that ID from:
vsi = mgr.create_instance(**nodes) print vsi["id"]
Or you can try with this method to create several severs at once: https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/managers/vs.py#L549
Also this link may help you with VLANS. http://sldn.softlayer.com/blog/phil/CCI-VLAN-Specification
Regards
Upvotes: 1
Reputation: 537
The Clusters and their EndPoints either public or private can be obtained using the next request:
https://$username:[email protected]/rest/v3/SoftLayer_Network_Storage/$networkStorageId/getObjectStorageConnectionInformation.json
Method: GET
Replace $username, $apiKey and $networkStorageId with your information.
I'm not sure if this fullfills all your requirements, but it might be the starting point to replicate the result from this request to ansible or python. Nevertheless I'm going to update this with python code. Let me know if this request could help your implementation.
Upvotes: 0