尽管指定,但部分 Softlayer 批量 VMI 订单被提供到错误的 VLAN

Part of Softlayer bulk VMI order gets provisioned into wrong VLAN despite specified

我正在使用 Softlayer API 和 python 脚本在我的 SL 帐户中订购虚拟机。在脚本中,我定义了一个应该放置机器的 VLAN。在我的帐户中,我可以看到此 VLAN 中有一个 /26 私有子网。当我一次部署 2-3 台机器时,该脚本工作正常。但是,如果我使用完全相同的脚本来部署 60 个虚拟机,即使在执行脚本时指定的 VLAN 为空,大多数机器也会以某种方式被放置到具有不同 IP 地址的新 VLAN 中。通常这不是问题,但我正在使用 Vyatta 创建 IPsec 隧道,因此我需要指定哪个 VLAN / 子网可以使用该隧道。脚本中是否需要更改某些内容?

createoder.py

import SoftLayer
import ast
from pprint import pprint as pp

templateId = 1631417 #Template ID which has been retrieved prior to executing the script
quantity = 60 #Number of VMs to deploy

#Create client and manager for further commands
client = SoftLayer.create_client_from_env(username='myuser' , 
api_key='myapikey') #masked for publishing reasons
mgr = SoftLayer.VSManager(client)

#Display available templates within account
mask = "mask[id,name,note]"
imageTemplates = 
client['SoftLayer_Account'].getPrivateBlockDeviceTemplateGroups(mask=mask)
print("ID - Name - Note")
for template in imageTemplates:
    try:
        print("%s - %s - %s" % (template['id'], template['name'], 
template['note']))
    except KeyError:
        print("%s - %s - %s" % (template['id'], template['name'], 'None'))


#Prepare and execute order
for x in range(1, quantity+1): #Loop for creating the defined amount of VMs
    order = {
    'complexType': 'SoftLayer_Container_Product_Order_Virtual_Guest',
    'quantity': 1,
    'useHourlyPricing': True,
    'virtualGuests': [
    {'hostname': 'VM%d' % (x), 'domain': 'mydomain.com', 'privateNetworkOnlyFlag': True, 'primaryBackendNetworkComponent': {'networkVlanId': 1706321 }}
    ],
    'location': 449506,  # Frankfurt 02
    'packageId': 46,  # Virtual Cloud Server
    'prices': [
    {'id': 52307},  # 2 x 2.0 GHz Core private
    {'id': 51491},  # 4 GB RAM
    {'id': 905},  # Reboot / Remote Console
    #{'id': 26737},  # 100 Mbps Public & Private Networks
    {'id': 52429},  # 1 GB Private Network Uplink
    {'id': 1800},  # 0 GB Public Bandwidth
    {'id': 21},  # 1 IP Address
    {'id': 13887},  # 100 GB (Local)
    {'id': 55},  # Host Ping Monitoring
    {'id': 57},  # Email and Ticket Notifications
    {'id': 58},  # Automated Notification Response
    {'id': 420},  # Unlimited SSL VPN Users & 1 PPTP VPN User per account
    {'id': 418},  # Nessus Vulnerability Assessment & Reporting
    {'id': 175797}, # Microsoft Windows Server 2012R2 Standard
    #{'id': 29642},  # Microsoft Windows Firewall
    ],
    'imageTemplateId': templateId
    }
    #result = client['SoftLayer_Product_Order'].verifyOrder(order)
    result = client['SoftLayer_Product_Order'].placeOrder(order)
    pp(result)
    pp(x)

“目前设置一个Vlan,使用placeOrder方法,只能通过使用属性'hardware'(而不是使用'virtualGuests'属性)来进行,请进行以下更改到您的 python 脚本:

'hardware': [
{'hostname': 'test1', 'domain': 'mydomain.com', 'privateNetworkOnlyFlag': True, 'primaryBackendNetworkComponent': {'networkVlanId': 1706321 }}
],

并在执行脚本之前使用“verifyOrder”方法,以验证vlan是否分配成功。

您可以通过交换上述属性(“virtualGuests”与“硬件”)来验证之前提到的内容,并在下订单后检查这些属性的结果(为此使用 verifyOrder)。”