-->

Part of Softlayer bulk VMI order gets provisioned

2019-03-03 11:44发布

问题:

I am using the Softlayer API and a python script to order virtual machines within my SL account. Within the script I define a VLAN in which the machines should be placed. Within my account I can see a /26 private subnet within this VLAN. The script works fine when I deploy 2-3 machines at a time. However if I use the exact same script to deploy 60 VMs, somehow most of the machines will be placed into a new VLAN with different IP addresses, even though the specified VLAN was empty during the time of executing the script. Usually this would not be an issue, but I am using a Vyatta to create an IPsec tunnel and therefore I need to specify which VLAN / Subnet can use the tunnel. Is there something that needs to be changed within the script?

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)

回答1:

“Currently setting a Vlan, using the placeOrder method, can only be made by using only the property ‘hardware’ (instead of using ‘virtualGuests’ property) please make the following change to your python script:

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

and use the “verifyOrder” method before executing the script, in order to verify that the vlan was assigned successfully.

You may verify what’s mentioned before by exchanging the mentioned properties (‘virtualGuests’ vs ‘hardware’) and check the results for these properties after the order was placed (use verifyOrder for this).”