Skip to content

Commit 9e8c408

Browse files
some advanced quote ordering
1 parent 5269b41 commit 9e8c408

10 files changed

Lines changed: 465 additions & 285 deletions

File tree

classes/softlayer_account/index.xml

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -908,51 +908,45 @@ from pprint import pprint as pp
908908
class example():
909909

910910
def __init__(self):
911-
912911
self.client = SoftLayer.Client()
913-
self.mgr = SoftLayer.OrderingManager(self.client)
914-
915912

916-
def orderQuote(self, quote_id):
913+
def orderQuote(self, quote_id, dc_id = None, image_id = None, private_vlan = None, public_vlan = None):
917914
# If you have more than 1 server in the quote, you will need to append
918-
#
915+
# a copy of this for each VSI, with hostnames changed as needed
919916
guests = {
920917
'hostname': 'quotetest',
921918
'domain': 'example.com'
922-
923919
}
924-
920+
if public_vlan:
921+
guests.update({
922+
'primaryNetworkComponent': {
923+
"networkVlan": {"id": int(public_vlan)}}})
924+
if private_vlan:
925+
guests.update({
926+
"primaryBackendNetworkComponent": {
927+
"networkVlan": {"id": int(private_vlan)}}})
928+
925929
quote = self.client['Billing_Order_Quote']
926930
quote_container = quote.getRecalculatedOrderContainer(id=quote_id)
927-
container = quote_container['orderContainers'][0]
928931

932+
container = quote_container
929933
container['quantity'] = 1
930934
container['virtualGuests'] = []
931935
container['virtualGuests'].append(guests)
932936

933-
# SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_Order_MismatchedQuantity): The number of servers (2) does not match the order quantity (1).
934-
# the hardware variable was getting filled out for some reason, even though there were no hardware on this quote.
935-
container['hardware'] = None
937+
# container['provisionScripts'] = ['https://gist.githubusercontent.com/myscript.py']
938+
# container['sshKeys'] = [{'sshKeyIds': [660791]} ]
936939

940+
if image_id is not None:
941+
container['imageTemplateId'] = image_id
937942

938-
container['presetId'] = None
939-
container['provisionScripts'] = ['https://gist.githubusercontent.com/myscript.py']
940-
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
941-
# The order of containers passed in needs to match the order they are assigned to either hardware or virtualGuests
942-
container['sshKeys'] = [{'sshKeyIds': [1234]} ]
943+
if dc_id is not None:
944+
container['location'] = dc_id
943945

944-
# Edit this ID to change the location of the order.
945-
# this is AMS03
946-
container['location'] = 814994
947-
result = self.client['Product_Order'].verifyOrder(container)
946+
# result = self.client['Product_Order'].verifyOrder(container)
947+
result = self.client['Product_Order'].placeOrder(container)
948948
pp(result)
949949

950-
def getOrderContainer(self,quote_id):
951-
quote = self.client['Billing_Order_Quote']
952-
container = quote.getRecalculatedOrderContainer(id=quote_id)
953-
return container['orderContainers'][0]
954-
955-
956950
def listQuotes(self):
957951
quotes = self.client['SoftLayer_Account'].getActiveQuotes()
958952
pp(quotes)
@@ -965,16 +959,42 @@ class example():
965959
keys = self.client['SoftLayer_Account'].getSshKeys()
966960
pp(keys)
967961

962+
def listImageTemplates(self):
963+
mask = "mask[id,name,note]"
964+
imageTemplates = self.client['SoftLayer_Account'].getPrivateBlockDeviceTemplateGroups(mask=mask)
965+
print("ID - Name - Note")
966+
for template in imageTemplates:
967+
try:
968+
print("%s - %s - %s" % (template['id'], template['name'], template['note']))
969+
except KeyError:
970+
print("%s - %s - %s" % (template['id'], template['name'], 'None'))
971+
972+
def listVlansInLocation(self, location_id):
973+
mask = "mask[id,vlanNumber,primaryRouter[hostname,datacenter[id,name]]]"
974+
objfilter2 = { "networkVlans":
975+
{"primaryRouter":
976+
{"datacenter": { "id" : {"operation":location_id} } }
977+
}
978+
}
979+
subnets = self.client['SoftLayer_Account'].getNetworkVlans(mask=mask,filter=objfilter2)
980+
for subnet in subnets:
981+
print("%s, %s, %s" % ( subnet['id'], subnet['vlanNumber'], subnet['primaryRouter']['hostname']))
982+
983+
968984
if __name__ == "__main__":
969-
quote_id = 1942633
985+
quote_id = 1234
970986
main = example()
971-
# main.main()
987+
# main.listImageTemplates()
972988
# main.listQuotes()
973-
# quote = main.getOrderContainer(quote_id)
974-
# pp(quote)
975989
# main.listLocations()
990+
dal13 = 1854895
991+
ams03 = 814994
992+
dal09 = 449494
976993
# main.listSshKeys()
977-
main.orderQuote(quote_id)
994+
# main.listVlansInLocation(dal13)
995+
backend_vlan = 1400000 # 123, bcr06a.dal09
996+
front_vlan = 1400001 # 456, fcr06a.dal09
997+
main.orderQuote(quote_id, dc_id=dal09, private_vlan=backend_vlan,public_vlan=front_vlan )
978998

979999
</code></pre>
9801000
</description>

classes/softlayer_billing_order_quote/index.xml

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,51 +20,45 @@ from pprint import pprint as pp
2020
class example():
2121

2222
def __init__(self):
23-
2423
self.client = SoftLayer.Client()
25-
self.mgr = SoftLayer.OrderingManager(self.client)
26-
2724

28-
def orderQuote(self, quote_id):
25+
def orderQuote(self, quote_id, dc_id = None, image_id = None, private_vlan = None, public_vlan = None):
2926
# If you have more than 1 server in the quote, you will need to append
30-
#
27+
# a copy of this for each VSI, with hostnames changed as needed
3128
guests = {
3229
&#39;hostname&#39;: &#39;quotetest&#39;,
3330
&#39;domain&#39;: &#39;example.com&#39;
34-
3531
}
36-
32+
if public_vlan:
33+
guests.update({
34+
&#39;primaryNetworkComponent&#39;: {
35+
&amp;quot;networkVlan&amp;quot;: {&amp;quot;id&amp;quot;: int(public_vlan)}}})
36+
if private_vlan:
37+
guests.update({
38+
&amp;quot;primaryBackendNetworkComponent&amp;quot;: {
39+
&amp;quot;networkVlan&amp;quot;: {&amp;quot;id&amp;quot;: int(private_vlan)}}})
40+
3741
quote = self.client[&#39;Billing_Order_Quote&#39;]
3842
quote_container = quote.getRecalculatedOrderContainer(id=quote_id)
39-
container = quote_container[&#39;orderContainers&#39;][0]
4043

44+
container = quote_container
4145
container[&#39;quantity&#39;] = 1
4246
container[&#39;virtualGuests&#39;] = []
4347
container[&#39;virtualGuests&#39;].append(guests)
4448

45-
# SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_Order_MismatchedQuantity): The number of servers (2) does not match the order quantity (1).
46-
# the hardware variable was getting filled out for some reason, even though there were no hardware on this quote.
47-
container[&#39;hardware&#39;] = None
49+
# container[&#39;provisionScripts&#39;] = [&#39;https://gist.githubusercontent.com/myscript.py&#39;]
50+
# container[&#39;sshKeys&#39;] = [{&#39;sshKeyIds&#39;: [660791]} ]
4851

52+
if image_id is not None:
53+
container[&#39;imageTemplateId&#39;] = image_id
4954

50-
container[&#39;presetId&#39;] = None
51-
container[&#39;provisionScripts&#39;] = [&#39;https://gist.githubusercontent.com/myscript.py&#39;]
52-
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
53-
# The order of containers passed in needs to match the order they are assigned to either hardware or virtualGuests
54-
container[&#39;sshKeys&#39;] = [{&#39;sshKeyIds&#39;: [1234]} ]
55+
if dc_id is not None:
56+
container[&#39;location&#39;] = dc_id
5557

56-
# Edit this ID to change the location of the order.
57-
# this is AMS03
58-
container[&#39;location&#39;] = 814994
59-
result = self.client[&#39;Product_Order&#39;].verifyOrder(container)
58+
# result = self.client[&#39;Product_Order&#39;].verifyOrder(container)
59+
result = self.client[&#39;Product_Order&#39;].placeOrder(container)
6060
pp(result)
6161

62-
def getOrderContainer(self,quote_id):
63-
quote = self.client[&#39;Billing_Order_Quote&#39;]
64-
container = quote.getRecalculatedOrderContainer(id=quote_id)
65-
return container[&#39;orderContainers&#39;][0]
66-
67-
6862
def listQuotes(self):
6963
quotes = self.client[&#39;SoftLayer_Account&#39;].getActiveQuotes()
7064
pp(quotes)
@@ -77,16 +71,42 @@ class example():
7771
keys = self.client[&#39;SoftLayer_Account&#39;].getSshKeys()
7872
pp(keys)
7973

74+
def listImageTemplates(self):
75+
mask = &amp;quot;mask[id,name,note]&amp;quot;
76+
imageTemplates = self.client[&#39;SoftLayer_Account&#39;].getPrivateBlockDeviceTemplateGroups(mask=mask)
77+
print(&amp;quot;ID - Name - Note&amp;quot;)
78+
for template in imageTemplates:
79+
try:
80+
print(&amp;quot;%s - %s - %s&amp;quot; % (template[&#39;id&#39;], template[&#39;name&#39;], template[&#39;note&#39;]))
81+
except KeyError:
82+
print(&amp;quot;%s - %s - %s&amp;quot; % (template[&#39;id&#39;], template[&#39;name&#39;], &#39;None&#39;))
83+
84+
def listVlansInLocation(self, location_id):
85+
mask = &amp;quot;mask[id,vlanNumber,primaryRouter[hostname,datacenter[id,name]]]&amp;quot;
86+
objfilter2 = { &amp;quot;networkVlans&amp;quot;:
87+
{&amp;quot;primaryRouter&amp;quot;:
88+
{&amp;quot;datacenter&amp;quot;: { &amp;quot;id&amp;quot; : {&amp;quot;operation&amp;quot;:location_id} } }
89+
}
90+
}
91+
subnets = self.client[&#39;SoftLayer_Account&#39;].getNetworkVlans(mask=mask,filter=objfilter2)
92+
for subnet in subnets:
93+
print(&amp;quot;%s, %s, %s&amp;quot; % ( subnet[&#39;id&#39;], subnet[&#39;vlanNumber&#39;], subnet[&#39;primaryRouter&#39;][&#39;hostname&#39;]))
94+
95+
8096
if __name__ == &amp;quot;__main__&amp;quot;:
81-
quote_id = 1942633
97+
quote_id = 1234
8298
main = example()
83-
# main.main()
99+
# main.listImageTemplates()
84100
# main.listQuotes()
85-
# quote = main.getOrderContainer(quote_id)
86-
# pp(quote)
87101
# main.listLocations()
102+
dal13 = 1854895
103+
ams03 = 814994
104+
dal09 = 449494
88105
# main.listSshKeys()
89-
main.orderQuote(quote_id)
106+
# main.listVlansInLocation(dal13)
107+
backend_vlan = 1400000 # 123, bcr06a.dal09
108+
front_vlan = 1400001 # 456, fcr06a.dal09
109+
main.orderQuote(quote_id, dc_id=dal09, private_vlan=backend_vlan,public_vlan=front_vlan )
90110

91111
&lt;/code&gt;&lt;/pre&gt;
92112
</description>

classes/softlayer_location/index.xml

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,51 +20,45 @@ from pprint import pprint as pp
2020
class example():
2121

2222
def __init__(self):
23-
2423
self.client = SoftLayer.Client()
25-
self.mgr = SoftLayer.OrderingManager(self.client)
26-
2724

28-
def orderQuote(self, quote_id):
25+
def orderQuote(self, quote_id, dc_id = None, image_id = None, private_vlan = None, public_vlan = None):
2926
# If you have more than 1 server in the quote, you will need to append
30-
#
27+
# a copy of this for each VSI, with hostnames changed as needed
3128
guests = {
3229
&#39;hostname&#39;: &#39;quotetest&#39;,
3330
&#39;domain&#39;: &#39;example.com&#39;
34-
3531
}
36-
32+
if public_vlan:
33+
guests.update({
34+
&#39;primaryNetworkComponent&#39;: {
35+
&amp;quot;networkVlan&amp;quot;: {&amp;quot;id&amp;quot;: int(public_vlan)}}})
36+
if private_vlan:
37+
guests.update({
38+
&amp;quot;primaryBackendNetworkComponent&amp;quot;: {
39+
&amp;quot;networkVlan&amp;quot;: {&amp;quot;id&amp;quot;: int(private_vlan)}}})
40+
3741
quote = self.client[&#39;Billing_Order_Quote&#39;]
3842
quote_container = quote.getRecalculatedOrderContainer(id=quote_id)
39-
container = quote_container[&#39;orderContainers&#39;][0]
4043

44+
container = quote_container
4145
container[&#39;quantity&#39;] = 1
4246
container[&#39;virtualGuests&#39;] = []
4347
container[&#39;virtualGuests&#39;].append(guests)
4448

45-
# SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_Order_MismatchedQuantity): The number of servers (2) does not match the order quantity (1).
46-
# the hardware variable was getting filled out for some reason, even though there were no hardware on this quote.
47-
container[&#39;hardware&#39;] = None
49+
# container[&#39;provisionScripts&#39;] = [&#39;https://gist.githubusercontent.com/myscript.py&#39;]
50+
# container[&#39;sshKeys&#39;] = [{&#39;sshKeyIds&#39;: [660791]} ]
4851

52+
if image_id is not None:
53+
container[&#39;imageTemplateId&#39;] = image_id
4954

50-
container[&#39;presetId&#39;] = None
51-
container[&#39;provisionScripts&#39;] = [&#39;https://gist.githubusercontent.com/myscript.py&#39;]
52-
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
53-
# The order of containers passed in needs to match the order they are assigned to either hardware or virtualGuests
54-
container[&#39;sshKeys&#39;] = [{&#39;sshKeyIds&#39;: [1234]} ]
55+
if dc_id is not None:
56+
container[&#39;location&#39;] = dc_id
5557

56-
# Edit this ID to change the location of the order.
57-
# this is AMS03
58-
container[&#39;location&#39;] = 814994
59-
result = self.client[&#39;Product_Order&#39;].verifyOrder(container)
58+
# result = self.client[&#39;Product_Order&#39;].verifyOrder(container)
59+
result = self.client[&#39;Product_Order&#39;].placeOrder(container)
6060
pp(result)
6161

62-
def getOrderContainer(self,quote_id):
63-
quote = self.client[&#39;Billing_Order_Quote&#39;]
64-
container = quote.getRecalculatedOrderContainer(id=quote_id)
65-
return container[&#39;orderContainers&#39;][0]
66-
67-
6862
def listQuotes(self):
6963
quotes = self.client[&#39;SoftLayer_Account&#39;].getActiveQuotes()
7064
pp(quotes)
@@ -77,16 +71,42 @@ class example():
7771
keys = self.client[&#39;SoftLayer_Account&#39;].getSshKeys()
7872
pp(keys)
7973

74+
def listImageTemplates(self):
75+
mask = &amp;quot;mask[id,name,note]&amp;quot;
76+
imageTemplates = self.client[&#39;SoftLayer_Account&#39;].getPrivateBlockDeviceTemplateGroups(mask=mask)
77+
print(&amp;quot;ID - Name - Note&amp;quot;)
78+
for template in imageTemplates:
79+
try:
80+
print(&amp;quot;%s - %s - %s&amp;quot; % (template[&#39;id&#39;], template[&#39;name&#39;], template[&#39;note&#39;]))
81+
except KeyError:
82+
print(&amp;quot;%s - %s - %s&amp;quot; % (template[&#39;id&#39;], template[&#39;name&#39;], &#39;None&#39;))
83+
84+
def listVlansInLocation(self, location_id):
85+
mask = &amp;quot;mask[id,vlanNumber,primaryRouter[hostname,datacenter[id,name]]]&amp;quot;
86+
objfilter2 = { &amp;quot;networkVlans&amp;quot;:
87+
{&amp;quot;primaryRouter&amp;quot;:
88+
{&amp;quot;datacenter&amp;quot;: { &amp;quot;id&amp;quot; : {&amp;quot;operation&amp;quot;:location_id} } }
89+
}
90+
}
91+
subnets = self.client[&#39;SoftLayer_Account&#39;].getNetworkVlans(mask=mask,filter=objfilter2)
92+
for subnet in subnets:
93+
print(&amp;quot;%s, %s, %s&amp;quot; % ( subnet[&#39;id&#39;], subnet[&#39;vlanNumber&#39;], subnet[&#39;primaryRouter&#39;][&#39;hostname&#39;]))
94+
95+
8096
if __name__ == &amp;quot;__main__&amp;quot;:
81-
quote_id = 1942633
97+
quote_id = 1234
8298
main = example()
83-
# main.main()
99+
# main.listImageTemplates()
84100
# main.listQuotes()
85-
# quote = main.getOrderContainer(quote_id)
86-
# pp(quote)
87101
# main.listLocations()
102+
dal13 = 1854895
103+
ams03 = 814994
104+
dal09 = 449494
88105
# main.listSshKeys()
89-
main.orderQuote(quote_id)
106+
# main.listVlansInLocation(dal13)
107+
backend_vlan = 1400000 # 123, bcr06a.dal09
108+
front_vlan = 1400001 # 456, fcr06a.dal09
109+
main.orderQuote(quote_id, dc_id=dal09, private_vlan=backend_vlan,public_vlan=front_vlan )
90110

91111
&lt;/code&gt;&lt;/pre&gt;
92112
</description>

0 commit comments

Comments
 (0)