@@ -908,51 +908,45 @@ from pprint import pprint as pp
908908class 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+ & quot;networkVlan& quot;: {& quot;id& quot;: int(public_vlan)}}})
924+ if private_vlan:
925+ guests.update({
926+ & quot;primaryBackendNetworkComponent& quot;: {
927+ & quot;networkVlan& quot;: {& quot;id& quot;: 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 = & quot;mask[id,name,note]& quot;
964+ imageTemplates = self.client[' SoftLayer_Account' ].getPrivateBlockDeviceTemplateGroups(mask=mask)
965+ print(& quot;ID - Name - Note& quot;)
966+ for template in imageTemplates:
967+ try:
968+ print(& quot;%s - %s - %s& quot; % (template[' id' ], template[' name' ], template[' note' ]))
969+ except KeyError:
970+ print(& quot;%s - %s - %s& quot; % (template[' id' ], template[' name' ], ' None' ))
971+
972+ def listVlansInLocation(self, location_id):
973+ mask = & quot;mask[id,vlanNumber,primaryRouter[hostname,datacenter[id,name]]]& quot;
974+ objfilter2 = { & quot;networkVlans& quot;:
975+ {& quot;primaryRouter& quot;:
976+ {& quot;datacenter& quot;: { & quot;id& quot; : {& quot;operation& quot;:location_id} } }
977+ }
978+ }
979+ subnets = self.client[' SoftLayer_Account' ].getNetworkVlans(mask=mask,filter=objfilter2)
980+ for subnet in subnets:
981+ print(& quot;%s, %s, %s& quot; % ( subnet[' id' ], subnet[' vlanNumber' ], subnet[' primaryRouter' ][' hostname' ]))
982+
983+
968984if __name__ == & quot;__main__& quot;:
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 >
0 commit comments