Created
June 18, 2010 19:09
-
-
Save softlayer/444067 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| # Order a new CDN account | |
| # | |
| # Build a SoftLayer_Container_Product_Order_Network_ContentDelivery_Account | |
| # object for a new CDN account order and pass it to the SoftLayer_Product_Order | |
| # API service to order it. In this carsre we'll order a pay as you go bandwidth | |
| # and storage CDN accopunt. See below for more details. | |
| # | |
| # This assumes you're using the SoftLayer API Perl client | |
| # <http://github.com/softlayer/softlayer-api-perl-client>. | |
| # | |
| # Important manual pages: | |
| # http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_ContentDelivery_Account | |
| # http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_ContentDelivery_Account | |
| # http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price | |
| # http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Order/verifyOrder | |
| # http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Order/placeOrder | |
| # | |
| # License: http://sldn.softlayer.com/article/License | |
| # Author: SoftLayer Technologies, Inc. <[email protected]> | |
| # Set this to the path of the SoftLayer API Perl client. | |
| use lib '/path/to/client/'; | |
| use SoftLayer::API::SOAP; | |
| use strict; | |
| use Data::Dumper; | |
| # Your SoftLayer API username and key. | |
| # | |
| # Generate an API key at the SoftLayer Customer Portal: | |
| # https://manage.softlayer.com/Administrative/apiKeychain | |
| my $apiUsername = 'set me!'; | |
| my $apiKey = 'set me too!'; | |
| # Your CDN account's name. | |
| # | |
| # Your CDN account name is used in your CDN account's URLs. For instance: | |
| # http://http.cdnlayer.com/myCdnAccount is used for all static HTTP CDN content | |
| # hosted under myCdnAccount's account. | |
| my $cdnAccountName = "myCdnAccount"; | |
| # The ids of the items you wish purchase in your CDN order. | |
| # | |
| # Every item in SoftLayer's product catalog is assigned an id. Use these ids to | |
| # tell the SoftLayer API which options you want for your CDN account. Use the | |
| # getActivePackages() method in the SoftLayer_Account API service to get a list | |
| # of available item and price options per available package. | |
| my @orderPrices = ( | |
| # Bandwidth plans. | |
| 1661, # Pay as you go CDN bandwidth | |
| #1662, # 250GB CDN Bandwidth | |
| #1663, # 500GB CDN Bandwidth | |
| #1664, # 1000GB CDN Bandwidth | |
| #1665, # 2000GB CDN Bandwidth | |
| #1900, # 5000GB CDN Bandwidth | |
| # CDN Storage options. You must specify a storage option in addition to a | |
| # bandwidth plan if you wish to use a POP pull CDN Account. Origin pull CDN | |
| # accounts have no local storage and do not require a storage plan. | |
| #1666, # 25GB CDN Storage | |
| #1667, # 50GB CDN Storage | |
| #1668, # 100GB CDN Storage | |
| #1669, # 250GB CDN Storage | |
| 1672, # Pay as you go CDN Storage | |
| ); | |
| # The SoftLayer API's ordering system requires your order's price records | |
| # packaged like a SoftLayer_Item_Price object, but you only have to specify that | |
| # item's id for the ordering system to know what you want. Re-organize your | |
| # order prices into an array of hashes, each with a single 'id' key populated. | |
| my @orderTemplatePrices; | |
| for my $priceId (@orderPrices) { | |
| push(@orderTemplatePrices, bless({ | |
| id => $priceId, | |
| }, 'slapi:SoftLayer_Product_Item_Price')); | |
| } | |
| # A CDN order only requires an account name and price ids for your CDN | |
| # account's bandwidth and storage options. There's no product catalog package | |
| # ids for CDN accounts, so set our order's packageId to 0. | |
| # | |
| # Bless the order template as a | |
| # SoftLayer_Container_Product_Order_Network_ContentDelivery_Account SOAP | |
| # object. Our ordering system determines what you're trying to order based on | |
| # the type or order container you send to it. | |
| my $orderTemplate = bless({ | |
| packageId => 0, | |
| quantity => 1, | |
| cdnAccountName => $cdnAccountName, | |
| prices => [ @orderTemplatePrices ], | |
| }, 'slapi:SoftLayer_Container_Product_Order_Network_ContentDelivery_Account'); | |
| # Declare a new API service object for the SoftLayer_Product_Order API service. | |
| my $client = SoftLayer::API::SOAP->new('SoftLayer_Product_Order', undef, $apiUsername, $apiKey); | |
| # verifyOrder() will check your order for errors. Replace this with a call to | |
| # placeOrder() when you're ready to order. Both calls return a receipt object | |
| # that you can use for your records. | |
| # | |
| # Once your order is placed it'll go through SoftLayer's approval and | |
| # provisioning process. When it's done you'll have a new | |
| # SoftLayer_Network_ContentDeliveryAccount object and CDN account ready to use. | |
| my $receipt = $client->verifyOrder($orderTemplate); | |
| if ($receipt->fault) { | |
| die 'There was an error in your order. ' . $receipt->faultstring; | |
| } | |
| # Pretty print the order receipt. | |
| print Dumper($receipt->result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment