如何在 Softlayer 中的同一 Private/Public 局域网中创建集群?
How can I create a cluster in the Same Private/Public lan in Softlayer?
我很想在同一个 newtork 中创建一个集群,borh private 和 public,但我做不到
我试过ansible,但没有用
现在我正在尝试使用以下 python 代码
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.
这有时有效,但并非总是有效。
我尝试使用 public_vlan 和 private_vlan 属性,但是当我这样做时服务器没有被实例化。
更新 尼尔森回答后。
好的,所以我必须更改我的 python 代码以从第一个创建的工作站获取网络,并将其设置在集群中的以下服务器中。
如果没有可用的网络 ip,我需要实例化的服务器数量会怎样?
有没有办法确定哪个网络更适合实例化我的集群?
是否有列出可用网络的服务?
可以使用下一个请求获得 public 或私有的集群及其端点:
https://$username:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/$networkStorageId/getObjectStorageConnectionInformation.json
Method: GET
用您的信息替换 $username、$apiKey 和 $networkStorageId。
我不确定这是否满足您的所有要求,但这可能是将此请求的结果复制到 ansible 或 python 的起点。不过,我将使用 python 代码对其进行更新。让我知道此请求是否有助于您的实施。
如果您希望您的机器位于同一网络中,您需要在订单中为 public 和专用网络指定 VLAN,否则无法保证它们最终会位于同一网络中。请参阅有关订单的示例:
https://softlayer.github.io/python/create_vsi_options/
如果您的服务器未启动,这可能是 softlayer 供应过程的问题我建议您向 softlayer 提交票证并询问他们为什么您的服务器未启动。
关于你的另一个错误(与一次订单有关的错误),这是对你的帐户的限制,如果你想更改它,你需要与一些softlayer的销售人员交谈。您可以修复您当前的代码,添加一个等待直到订单完成,然后下一个订单,softlayer Python APi 有一个方法,请参阅:
https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/managers/vs.py#L393
您只需在代码中添加如下内容:
示例::
# 一旦 vsi 12345 准备就绪,或在 10 次检查后,将 return
准备就绪 = mgr.wait_for_ready(12345, 10)
数字“12345”是您刚刚订购的服务器的 ID,您可以从以下位置获取该 ID:
vsi = mgr.create_instance(**节点)
打印 vsi["id"]
或者您可以尝试使用此方法一次创建多个服务器:
https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/managers/vs.py#L549
另外这个 link 可以帮助您使用 VLANS。
http://sldn.softlayer.com/blog/phil/CCI-VLAN-Specification
此致
关于你的问题"Is there a service for listing the available networks?"。试试这个脚本,它将有助于从您的帐户的 vlan 中获得 空闲插槽 (免费 IP 地址):
"""
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. <sldn@softlayer.com>
"""
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)
我很想在同一个 newtork 中创建一个集群,borh private 和 public,但我做不到 我试过ansible,但没有用 现在我正在尝试使用以下 python 代码
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.
这有时有效,但并非总是有效。 我尝试使用 public_vlan 和 private_vlan 属性,但是当我这样做时服务器没有被实例化。
更新 尼尔森回答后。 好的,所以我必须更改我的 python 代码以从第一个创建的工作站获取网络,并将其设置在集群中的以下服务器中。 如果没有可用的网络 ip,我需要实例化的服务器数量会怎样? 有没有办法确定哪个网络更适合实例化我的集群? 是否有列出可用网络的服务?
可以使用下一个请求获得 public 或私有的集群及其端点:
https://$username:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/$networkStorageId/getObjectStorageConnectionInformation.json
Method: GET
用您的信息替换 $username、$apiKey 和 $networkStorageId。
我不确定这是否满足您的所有要求,但这可能是将此请求的结果复制到 ansible 或 python 的起点。不过,我将使用 python 代码对其进行更新。让我知道此请求是否有助于您的实施。
如果您希望您的机器位于同一网络中,您需要在订单中为 public 和专用网络指定 VLAN,否则无法保证它们最终会位于同一网络中。请参阅有关订单的示例:
https://softlayer.github.io/python/create_vsi_options/
如果您的服务器未启动,这可能是 softlayer 供应过程的问题我建议您向 softlayer 提交票证并询问他们为什么您的服务器未启动。
关于你的另一个错误(与一次订单有关的错误),这是对你的帐户的限制,如果你想更改它,你需要与一些softlayer的销售人员交谈。您可以修复您当前的代码,添加一个等待直到订单完成,然后下一个订单,softlayer Python APi 有一个方法,请参阅:
https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/managers/vs.py#L393
您只需在代码中添加如下内容:
示例:: # 一旦 vsi 12345 准备就绪,或在 10 次检查后,将 return 准备就绪 = mgr.wait_for_ready(12345, 10)
数字“12345”是您刚刚订购的服务器的 ID,您可以从以下位置获取该 ID:
vsi = mgr.create_instance(**节点) 打印 vsi["id"]
或者您可以尝试使用此方法一次创建多个服务器: https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/managers/vs.py#L549
另外这个 link 可以帮助您使用 VLANS。 http://sldn.softlayer.com/blog/phil/CCI-VLAN-Specification
此致
关于你的问题"Is there a service for listing the available networks?"。试试这个脚本,它将有助于从您的帐户的 vlan 中获得 空闲插槽 (免费 IP 地址):
"""
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. <sldn@softlayer.com>
"""
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)