softlayer_api 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.textile +36 -0
- data/README.textile +17 -7
- data/examples/account_info.rb +6 -3
- data/examples/account_servers.rb +48 -0
- data/examples/create_ticket.rb +33 -22
- data/examples/open_tickets.rb +14 -19
- data/examples/order_bare_metal_package.rb +154 -0
- data/examples/order_virtual_server.rb +85 -0
- data/examples/ticket_info.rb +13 -14
- data/lib/softlayer/APIParameterFilter.rb +100 -23
- data/lib/softlayer/Account.rb +140 -0
- data/lib/softlayer/BareMetalServer.rb +233 -0
- data/lib/softlayer/BareMetalServerOrder.rb +227 -0
- data/lib/softlayer/BareMetalServerOrder_Package.rb +162 -0
- data/lib/softlayer/Client.rb +54 -9
- data/lib/softlayer/Config.rb +2 -3
- data/lib/softlayer/DynamicAttribute.rb +170 -0
- data/lib/softlayer/ModelBase.rb +141 -0
- data/lib/softlayer/ObjectFilter.rb +61 -21
- data/lib/softlayer/ObjectMaskParser.rb +157 -0
- data/lib/softlayer/ObjectMaskProperty.rb +83 -0
- data/lib/softlayer/ObjectMaskToken.rb +107 -0
- data/lib/softlayer/ObjectMaskTokenizer.rb +88 -0
- data/lib/softlayer/ProductItemCategory.rb +137 -0
- data/lib/softlayer/ProductPackage.rb +196 -0
- data/lib/softlayer/Server.rb +245 -0
- data/lib/softlayer/Service.rb +12 -9
- data/lib/softlayer/Ticket.rb +210 -0
- data/lib/softlayer/VirtualServer.rb +388 -0
- data/lib/softlayer/VirtualServerOrder.rb +263 -0
- data/lib/softlayer/base.rb +9 -9
- data/lib/softlayer/object_mask_helpers.rb +46 -18
- data/lib/softlayer_api.rb +15 -0
- metadata +49 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec9821bee592ef106f6fd3cc00af8c1b980766a8
|
4
|
+
data.tar.gz: 3bda1cb83614eb4a8876a96aaad86d3104825ddb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b885072f2075801dc2f0a5dddb3ca0f902c560522d4cd2b9c7fb87f51761242a197fdd8c550a6a3ef2f10dabe6fb6c6fe8433964271f653a4c7afaac4b7618e5
|
7
|
+
data.tar.gz: 5c182f1f9633948a8b94bc7824f383434e23f468a9eb3a849b719849f56cbafda0af793a0c9e95fbfeca166b1f676da94963b1d3f7b8eaa9c3541daeb6d3f74a
|
data/CHANGELOG.textile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*2.1.0*
|
2
|
+
* Began implementing a model framework that allows Ruby developers to work with elements in the SoftLayer API in a more object-oriented fashion. The first release of this framework includes the Ticket, VirtualServer, and BareMetalServer classes.
|
3
|
+
|
4
|
+
*2.0.1*
|
5
|
+
* Fix broken gem configparser dependency
|
6
|
+
|
7
|
+
*2.0.0*
|
8
|
+
* Switched the Ruby API client to use XML-RPC when calling the SoftLayer API rather than using the REST-like interface.
|
9
|
+
* Result limits are now specified using @result_limit(offset,limit)@.
|
10
|
+
The @result_offset@ API filter has been removed.
|
11
|
+
* The @object_mask@ call modifier no longer accepts Ruby structures. It accepts strings that are Object Masks in the "Extended Object Mask":http://sldn.softlayer.com/article/Object-Masks format.
|
12
|
+
* Changed the mechanism for obtaining services to include the Client class. This makes the Ruby API very similar to the API presented by the Python bindings. The old mechanism for obtaining services still works to preserve backward compatibility but you will receive deprecation warnings in debug mode.
|
13
|
+
|
14
|
+
*1.0.8*
|
15
|
+
* Set a default User-Agent string to be sent with all requests to SoftLayer API. Provide interface to set a custom User-Agent string.
|
16
|
+
|
17
|
+
*1.0.7*
|
18
|
+
* Calls to the @getObject@ method of any service should not take parameters. The gem now warns if you make this type of call and ignores the parameters. This prevents @SoftLayer_Virtual_Guest::getObject@ from accidentally creating (billable) VirtualServer instances.
|
19
|
+
|
20
|
+
*1.0.6*
|
21
|
+
* Make all API calls with either a @GET@ or a @POST@ as the HTTP verb.
|
22
|
+
|
23
|
+
*1.0.5*
|
24
|
+
* Fixed a bug where empty hashes and empty arrays would not generate meaningful object masks
|
25
|
+
|
26
|
+
*1.0.4*
|
27
|
+
* Fixed a bug where the @result_limit@ and @result_offset@ object filters were just not working.
|
28
|
+
|
29
|
+
*1.0.3*
|
30
|
+
* Added a request filter to add result limits to request. Submitted by JN. Thanks!
|
31
|
+
|
32
|
+
*1.0.2*
|
33
|
+
* We have some API routines that start with 'get' but expect arguments anyway. The code now uses HTTP POST to send requests for which the user has provided arguments regardless of the name of the routine.
|
34
|
+
|
35
|
+
*1.0*, *1.0.1*
|
36
|
+
* Initial release of the gem
|
data/README.textile
CHANGED
@@ -5,7 +5,7 @@ The SoftLayer API Client for Ruby is a library for connecting to and calling the
|
|
5
5
|
<div id="note" style="margin: 1em; padding: 0.5em; background-color: #fcfcfc; border: 1px solid black">
|
6
6
|
*Important Note*
|
7
7
|
|
8
|
-
|
8
|
+
If you are arriving at this build from verison 1.0 of the @softlayer_api@ gem, you will probably have to change some of your existing scripts. Please see "What's New":#whats-new for details.
|
9
9
|
</div>
|
10
10
|
|
11
11
|
h2. Overview
|
@@ -24,13 +24,23 @@ The Ruby client has been tested using a wide variety of Ruby implementations inc
|
|
24
24
|
|
25
25
|
A network connection is required, and a valid SoftLayer API username and api key are required to call the SoftLayer API. A connection to the SoftLayer private network is required to connect to SoftLayer's private network API endpoints.
|
26
26
|
|
27
|
-
h2(#
|
27
|
+
h2(#whats-new). What's New
|
28
|
+
|
29
|
+
The softlayer_api gem no longer supports Ruby 1.8.x
|
30
|
+
|
31
|
+
**Version 2.1** of @softlayer_api@ builds an object model of SoftLayer clases on top of the low-level SoftLayer API calls. The object model provides a high-level interface to the elements within the SoftLayer environment and encapsulates some of the details of the "raw" SoftLayer API.
|
32
|
+
|
33
|
+
|
34
|
+
With this first release, the Object Model provides classes for the SoftLayer Account, Bare Metal and Virutal servers, and Tickets. The model also provides classes to help you place orders for both Bare Metal and Virtual Servers. The class structure is not meant to be comprehensive. Our goal is to provide a simple API for performing common operations.
|
35
|
+
|
36
|
+
Interface documentation for the new object hierarchy is available in the gem's source. More comprehensive documentation including a design guide for new clases and a contribution guide for developers will be added in the future.
|
37
|
+
|
38
|
+
**Version 2.0** of the @softlayer_api@ gem changes the protocol used to communicate with the SoftLayer API from REST to XML-RPC. This change alone should not require any changes to scripts written to the version 1.0 gem. However there are two new behaviors which will require existing version 1.0 scripts to change:
|
28
39
|
|
29
|
-
Version 2.0 of the @softlayer_api@ gem changes the protocol used to communicate with the SoftLayer API from REST to XML-RPC. This change should not require any changes to existing scripts. However there are two new behaviors which may require you to change existing scripts:
|
30
40
|
* Object Masks are now sent to the server using the "Extended Object Mask Format":http://sldn.softlayer.com/article/Object-Masks.
|
31
41
|
* Result limits are now specified using a single call rather than requiring two
|
32
42
|
|
33
|
-
|
43
|
+
The gem now allows you to specify your SoftLayer username and API key through a config file. See "Providing authentication in a config file":#config_authorization for more information.
|
34
44
|
|
35
45
|
h3. XML-RPC
|
36
46
|
|
@@ -76,7 +86,7 @@ h3. Authentication
|
|
76
86
|
|
77
87
|
That instance will have to know your "API authentication information":http://sldn.softlayer.com/article/Authenticating_to_the_SoftLayer_API consisting of your account username and API key. In addition, you will have to select an endpoint, the web address the client will use to contact the SoftLayer API. You may provide this information in a configuration file, through global variables, or by passing them to the constructor.
|
78
88
|
|
79
|
-
h4. Providing authentication in a config file
|
89
|
+
h4(#config_authorization). Providing authentication in a config file
|
80
90
|
|
81
91
|
The Ruby client will look for a configuration file that can provide the username and api_key for requests. A sample configuraiton file looks like this:
|
82
92
|
|
@@ -187,7 +197,7 @@ If you wish to limit the volume of information that the server returns about a p
|
|
187
197
|
|
188
198
|
The arguments to @object_mask@ must strings. Each string should be a well defined Object Mask as defined in the "SLDN documentation":http://sldn.softlayer.com/article/Object-Masks.
|
189
199
|
|
190
|
-
To look at some examples, consider the following object from the server. It has four properties: @id@, @title@, @createDate@ and @modifyDate@.
|
200
|
+
To look at some examples, consider the following object from the server. It has four properties: @id@, @title@, @createDate@ and @modifyDate@. It also has an entity, @assignedUser@. The @assignedUser@ entity has three properties: @id@, @username@, and @health@.
|
191
201
|
|
192
202
|
<pre style="border:1pt solid black;background:#eee;padding:0.5em;margin:0.5em"><code style="font-family:Menlo,Monaco,monospace;font-size:9pt">{
|
193
203
|
"id"=>1736473,
|
@@ -232,7 +242,7 @@ We can identify a particular set of attributes we are interested in by combining
|
|
232
242
|
=> {"assignedUser"=>{"id"=>14, "health"=>"Fantastic"}}
|
233
243
|
</code></pre>
|
234
244
|
|
235
|
-
Object masks are sent to the server and applied on the server side.
|
245
|
+
Object masks are sent to the server and applied on the server side. Errors in the object mask format will lead to exceptions being thrown by the SoftLayer API. By carefully choosing an Object Mask, you can limit amount of information transferred from the server which may improve bandwidth and processing time.
|
236
246
|
|
237
247
|
You @object_with_id@ should only be called once in any calling sequence. You may call @object_mask@ multiple times, but the server may generate a warning if the Object Masks ask for duplicate properties of some object.
|
238
248
|
|
data/examples/account_info.rb
CHANGED
@@ -26,13 +26,16 @@ require 'pp'
|
|
26
26
|
|
27
27
|
begin
|
28
28
|
softlayer_client = SoftLayer::Client.new(
|
29
|
-
:username => "joecustomer" # enter your username here
|
30
|
-
:api_key => "feeddeadbeefbadf00d..." # enter your api key here
|
29
|
+
# :username => "joecustomer" # enter your username here
|
30
|
+
# :api_key => "feeddeadbeefbadf00d..." # enter your api key here
|
31
31
|
)
|
32
32
|
|
33
|
-
#
|
33
|
+
# Demonstrates using the low-level capabilities of the softlayer_api
|
34
|
+
# gem to get directly at methods in the SoftLayer API and extract
|
35
|
+
# data from them.
|
34
36
|
account_service = softlayer_client['Account'];
|
35
37
|
account = account_service.getObject
|
38
|
+
|
36
39
|
pp account
|
37
40
|
rescue Exception => exception
|
38
41
|
puts "Unable to retrieve account information: #{exception}"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 SoftLayer Technologies, Inc. All rights reserved.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'rubygems'
|
24
|
+
require 'softlayer_api'
|
25
|
+
require 'pp'
|
26
|
+
|
27
|
+
# We can set the default client to be our client and that way
|
28
|
+
# we can avoid supplying it later
|
29
|
+
SoftLayer::Client.default_client = SoftLayer::Client.new(
|
30
|
+
# :username => "joecustomer" # enter your username here
|
31
|
+
# :api_key => "feeddeadbeefbadf00d..." # enter your api key here
|
32
|
+
)
|
33
|
+
|
34
|
+
account = SoftLayer::Account.account_for_client()
|
35
|
+
|
36
|
+
# grab a list of all the servers on the account.
|
37
|
+
servers = account.servers
|
38
|
+
|
39
|
+
# measure their fully qualified domain names so we can print a pretty table
|
40
|
+
max_name_len = servers.inject(0) { |max_name, server| [max_name, server.fullyQualifiedDomainName.length].max }
|
41
|
+
|
42
|
+
printf "%#{-max_name_len}s\tPrimary Public IP\n", "Server FQDN"
|
43
|
+
printf "%#{-max_name_len}s\t-----------------\n", "-----------"
|
44
|
+
|
45
|
+
servers.each do |server|
|
46
|
+
ip_field = server.primary_public_ip ? server.primary_public_ip : "No Public Interface"
|
47
|
+
printf "%#{-max_name_len}s\t#{ip_field}\n", server.fullyQualifiedDomainName
|
48
|
+
end
|
data/examples/create_ticket.rb
CHANGED
@@ -24,33 +24,44 @@ require 'rubygems'
|
|
24
24
|
require 'softlayer_api'
|
25
25
|
require 'pp'
|
26
26
|
|
27
|
-
|
28
|
-
#
|
29
|
-
|
30
|
-
|
27
|
+
softlayer_client = SoftLayer::Client.new(
|
28
|
+
# :username => "joecustomer" # enter your username here
|
29
|
+
# :api_key => "feeddeadbeefbadf00d..." # enter your api key here
|
30
|
+
)
|
31
31
|
|
32
|
-
softlayer_client = SoftLayer::Client.new()
|
33
32
|
begin
|
34
|
-
#
|
35
|
-
|
36
|
-
|
33
|
+
# To create a ticket we have to assign the ticket to some user so
|
34
|
+
# assign our new ticket to the current user
|
35
|
+
account = SoftLayer::Account.account_for_client(softlayer_client)
|
36
|
+
account_user = account.service.getCurrentUser
|
37
|
+
my_user_id = account_user["id"]
|
38
|
+
|
39
|
+
# We also need a subject for the ticket. Subjects are specified by id
|
40
|
+
# This code prints out a table of all the ticket subjects with their
|
41
|
+
# ids:
|
42
|
+
ticket_subjects = SoftLayer::Ticket.ticket_subjects(softlayer_client)
|
43
|
+
ticket_subjects.each do |subject|
|
44
|
+
puts "#{subject['id']}\t#{subject['name']}"
|
45
|
+
end
|
46
|
+
|
47
|
+
# For this example we'll use 'Public Network Question' as the subject. That's id 1022
|
48
|
+
public_network_question_id = 1022
|
37
49
|
|
38
|
-
#
|
39
|
-
#
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
},
|
48
|
-
"This is a test ticket created from a Ruby client")
|
50
|
+
# A title is optional, but we'll provide one and we offer the body of the ticket
|
51
|
+
# remember to pass the client to create_standard_ticket
|
52
|
+
new_ticket = SoftLayer::Ticket.create_standard_ticket(
|
53
|
+
:client => softlayer_client,
|
54
|
+
:title => "This is a test ticket, please simply close it",
|
55
|
+
:body => "This test ticket was created to test the Ruby API client. Please ignore it.",
|
56
|
+
:subject_id => public_network_question_id,
|
57
|
+
:assigned_user_id => my_user_id
|
58
|
+
)
|
49
59
|
|
50
|
-
puts "Created a new ticket : #{new_ticket
|
60
|
+
puts "Created a new ticket : #{new_ticket.id} - #{new_ticket.title}"
|
61
|
+
|
62
|
+
# we can also add an update to the ticket:
|
63
|
+
new_ticket.update("This is a ticket update sent from the Ruby library")
|
51
64
|
|
52
|
-
# add an update to the newly created ticket.
|
53
|
-
pp ticket_service.object_with_id(new_ticket['id']).edit({}, "This is a ticket update sent from the Ruby library")
|
54
65
|
rescue Exception => exception
|
55
66
|
$stderr.puts "An exception occurred while trying to complete the SoftLayer API calls #{exception}"
|
56
67
|
end
|
data/examples/open_tickets.rb
CHANGED
@@ -24,27 +24,22 @@ require 'rubygems'
|
|
24
24
|
require 'softlayer_api'
|
25
25
|
require 'pp'
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
# One way to provide a username and api key is to provide them
|
28
|
+
# as globals.
|
29
|
+
# $SL_API_USERNAME = "joecustomer" # enter your username here
|
30
|
+
# $SL_API_KEY = "feeddeadbeefbadf00d..." # enter your api key here
|
29
31
|
|
30
|
-
|
32
|
+
# The client constructed here must get it's credentials from somewhere
|
33
|
+
# In this script you might uncomment the globals above and assign your
|
34
|
+
# credentials there
|
35
|
+
SoftLayer::Client.default_client = SoftLayer::Client.new()
|
31
36
|
|
32
|
-
#
|
33
|
-
|
34
|
-
account_service = softlayer_client.service_named("Account")
|
37
|
+
# The openTickets routine will pick up the default client established above.
|
38
|
+
open_tickets = SoftLayer::Ticket.open_tickets()
|
35
39
|
|
36
|
-
open_tickets
|
37
|
-
open_tickets.each { |ticket| puts "#{ticket['id']} - #{ticket['title']}" }
|
38
|
-
|
39
|
-
# Now use the ticket service to get a each ticket (by ID) and a subset of the
|
40
|
-
# information known about it. We've already collected this information above,
|
41
|
-
# but this will demonstrate using an object mask to filter the results from
|
42
|
-
# the server.
|
43
|
-
ticket_service = softlayer_client["Ticket"]
|
40
|
+
open_tickets.sort!{ |lhs, rhs| -(lhs.lastEditDate <=> rhs.lastEditDate) }
|
44
41
|
open_tickets.each do |ticket|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
puts "exception #{exception}"
|
49
|
-
end
|
42
|
+
printf "#{ticket.id} - #{ticket.title}"
|
43
|
+
|
44
|
+
ticket.has_updates? ? printf("\t*\n") : printf("\n")
|
50
45
|
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 SoftLayer Technologies, Inc. All rights reserved.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'rubygems'
|
24
|
+
require 'softlayer_api'
|
25
|
+
require 'pp'
|
26
|
+
|
27
|
+
# This example walks through the process putting together an order for
|
28
|
+
# a bare metal server using the SoftLayer::BareMetalServerOrder_Package class.
|
29
|
+
#
|
30
|
+
# The script uses verify_order to ensure the order constructed is
|
31
|
+
# valid. If you actually wanted to place an order for a server
|
32
|
+
# you would call place_order!
|
33
|
+
|
34
|
+
# Here is the product order code boiled down to a single routine without
|
35
|
+
# all the explaination found in the main body of code below. Skip down to
|
36
|
+
# that code for a better explaination of the steps involved in ordering
|
37
|
+
# a server.
|
38
|
+
def tl_dr_version
|
39
|
+
client = SoftLayer::Client.new(
|
40
|
+
# :username => "joecustomer" # enter your username here
|
41
|
+
# :api_key => "feeddeadbeefbadf00d..." # enter your api key here
|
42
|
+
)
|
43
|
+
|
44
|
+
# Select a package
|
45
|
+
quad_intel_package = SoftLayer::ProductPackage.package_with_id(client, 32)
|
46
|
+
|
47
|
+
# Find required Categories and fill config_options with defaults
|
48
|
+
config_options = {}
|
49
|
+
required_categories = quad_intel_package.configuration.select { |category| category.required? }
|
50
|
+
required_categories.each { |required_category| config_options[required_category.categoryCode] = required_category.default_option }
|
51
|
+
|
52
|
+
# Provide a value for missing config categories
|
53
|
+
config_options['server'] = 1417 # price id of Quad Processor Quad Core Intel 7420 - 2.13GHz (Dunnington) - 4 x 6MB / 8MB cache
|
54
|
+
|
55
|
+
# With all the config options in place we can now construct the product order.
|
56
|
+
server_order = SoftLayer::BareMetalServerOrder_Package.new(quad_intel_package, client)
|
57
|
+
server_order.location = 'sng01'
|
58
|
+
server_order.hostname = 'sample'
|
59
|
+
server_order.domain = 'softlayerapi.org'
|
60
|
+
server_order.configuration_options = config_options
|
61
|
+
|
62
|
+
begin
|
63
|
+
server_order.verify()
|
64
|
+
puts "The Order appears to be OK"
|
65
|
+
rescue Exception => e
|
66
|
+
puts "Order didn't verify :-( #{e}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
begin
|
71
|
+
client = SoftLayer::Client.new(
|
72
|
+
# :username => "joecustomer" # enter your username here
|
73
|
+
# :api_key => "feeddeadbeefbadf00d..." # enter your api key here
|
74
|
+
)
|
75
|
+
|
76
|
+
# Servers are ordered from ProductPackages. We first get a list of all the
|
77
|
+
# Bare Metal Server packages and print that list along with the package IDs
|
78
|
+
puts "Bare Metal Server Packages:"
|
79
|
+
packages = SoftLayer::ProductPackage.bare_metal_server_packages(client)
|
80
|
+
packages.each { |package| puts "#{package.id}\t#{package.name}"}
|
81
|
+
|
82
|
+
# For this example, we'll assume that we've selected the a package
|
83
|
+
# with an id of 32 representing a "Quad Processor, Quad Core Intel"
|
84
|
+
quad_intel_package = SoftLayer::ProductPackage.package_with_id(32, client)
|
85
|
+
|
86
|
+
# Now we need to now what ProductItemCategories are required to
|
87
|
+
# configure a server in that package. This code prints out a table
|
88
|
+
# of the required category codes with a description of each
|
89
|
+
puts "\nRequired Categories for '#{quad_intel_package.name}':"
|
90
|
+
required_categories = quad_intel_package.configuration.select { |category| category.required? }
|
91
|
+
max_code_length = required_categories.inject(0) { |max_code_length, category| [category.categoryCode.length, max_code_length].max }
|
92
|
+
printf "%#{max_code_length}s\tCategory Description\n", "Category Code"
|
93
|
+
printf "%#{max_code_length}s\t--------------------\n", "-------------"
|
94
|
+
required_categories.each { |category| printf "%#{max_code_length}s\t#{category.name}\n", category.categoryCode}
|
95
|
+
|
96
|
+
# We will need to provide values for each of the required category codes in our
|
97
|
+
# configuration_options. Let's see what configuration options are available for
|
98
|
+
# just one of the categories... Say 'os'
|
99
|
+
os_category = quad_intel_package.category('os')
|
100
|
+
config_options = os_category.configuration_options
|
101
|
+
puts "\nConfiguration options in the 'os' category:"
|
102
|
+
config_options.each { |option| printf "%5s\t#{option.description}\n", option.price_id }
|
103
|
+
|
104
|
+
# For this example, we'll choose the first os option that contains the string 'CentOS 6'
|
105
|
+
# in its description
|
106
|
+
os_config_option = config_options.find { |option| option.description =~ /CentOS 6/ }
|
107
|
+
|
108
|
+
# Let's begin choosing configuration_options with the default options in each required category
|
109
|
+
# where they can be found. Read the description of ProductItemCategory#default_option carefully
|
110
|
+
# to avoid surprises!
|
111
|
+
config_options = {}
|
112
|
+
required_categories.each { |required_category| config_options[required_category.categoryCode] = required_category.default_option }
|
113
|
+
|
114
|
+
# print out descriptions of the the configuration options that were discovered
|
115
|
+
puts "\nConfiguration with default options:"
|
116
|
+
max_category_length = config_options.inject(0) { |max_category_length, pair| [pair[0].length, max_category_length].max }
|
117
|
+
config_options.each { |category, config_option| printf "%#{max_category_length}s\t#{config_option ? config_option.description : 'no default'}\n", category }
|
118
|
+
|
119
|
+
# Regardless of the default values... we know we want the os selection we discovered above:
|
120
|
+
config_options['os'] = os_config_option
|
121
|
+
|
122
|
+
# And we can customize the default config by providing selections for any config categories
|
123
|
+
# we are interested in
|
124
|
+
config_options.merge! ({
|
125
|
+
'server' => 1417, # price id of Quad Processor Quad Core Intel 7420 - 2.13GHz (Dunnington) - 4 x 6MB / 8MB cache
|
126
|
+
'port_speed' => 274 # 1 Gbps Public & Private Network Uplinks
|
127
|
+
})
|
128
|
+
|
129
|
+
# We have a configuration for the server, we also need a location for the new server.
|
130
|
+
# The package can give us a list of locations. Let's print out that list
|
131
|
+
puts "\nData Centers for '#{quad_intel_package.name}':"
|
132
|
+
quad_intel_package.datacenter_options.each { |location| puts "\t#{location}"}
|
133
|
+
|
134
|
+
# With all the config options in place we can now construct the product order.
|
135
|
+
server_order = SoftLayer::BareMetalServerOrder_Package.new(quad_intel_package, client)
|
136
|
+
server_order.datacenter = 'sng01'
|
137
|
+
server_order.hostname = 'sample'
|
138
|
+
server_order.domain = 'softlayerapi.org'
|
139
|
+
server_order.configuration_options = config_options
|
140
|
+
|
141
|
+
# The order should be complete... call verify_order to make sure it's OK.
|
142
|
+
# you'll either get back a filled-out order, or you will get an
|
143
|
+
# exception. If you wanted to place the order, you would call 'place_order!' instead.
|
144
|
+
begin
|
145
|
+
server_order.verify()
|
146
|
+
puts "The Order appears to be OK"
|
147
|
+
rescue Exception => e
|
148
|
+
puts "Order didn't verify :-( #{e}"
|
149
|
+
end
|
150
|
+
|
151
|
+
rescue Exception => exception
|
152
|
+
$stderr.puts "An exception occurred while trying to complete the SoftLayer API calls #{exception}"
|
153
|
+
end
|
154
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 SoftLayer Technologies, Inc. All rights reserved.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'rubygems'
|
24
|
+
require 'softlayer_api'
|
25
|
+
require 'pp'
|
26
|
+
|
27
|
+
begin
|
28
|
+
# This sample walks through the creation of a Virtual Server.
|
29
|
+
# It explores techniques for discovering what configuration options
|
30
|
+
# exist, puts together an order, then sends that order to
|
31
|
+
# SoftLayer for verification.
|
32
|
+
|
33
|
+
client = SoftLayer::Client.new(
|
34
|
+
# :username => "joecustomer" # enter your username here
|
35
|
+
# :api_key => "feeddeadbeefbadf00d..." # enter your api key here
|
36
|
+
)
|
37
|
+
|
38
|
+
# We begin by creating a VirtualServerOrder and filling out the hostname and domain
|
39
|
+
# attributes.
|
40
|
+
server_order = SoftLayer::VirtualServerOrder.new(client)
|
41
|
+
server_order.hostname = "server1"
|
42
|
+
server_order.domain = "ruby-api-test.org"
|
43
|
+
|
44
|
+
# We must tell the system in which datacenter we want our server created
|
45
|
+
# We can ask the class to give us a list of options:
|
46
|
+
puts SoftLayer::VirtualServerOrder.datacenter_options(client).inspect
|
47
|
+
|
48
|
+
# The list will look something like ["ams01", "dal01", "dal05",...
|
49
|
+
# Let's put our server in the 'dal05' (Dallas 5) datacenter
|
50
|
+
server_order.datacenter = 'dal05'
|
51
|
+
|
52
|
+
# The order must know how many computing cores we want in our virtual
|
53
|
+
# server. Again we can ask the class for options. The result will
|
54
|
+
# be something like [1, 2, 4, 8, 12, 16]
|
55
|
+
# 2 sounds like a good number of cores for our simple server
|
56
|
+
puts SoftLayer::VirtualServerOrder.core_options(client).inspect
|
57
|
+
server_order.cores = 2
|
58
|
+
|
59
|
+
# We must indicate how much memory the virtual server should have.
|
60
|
+
# Again we can query for options and select a good value
|
61
|
+
puts SoftLayer::VirtualServerOrder.memory_options(client).inspect
|
62
|
+
server_order.memory = 2 #GB
|
63
|
+
|
64
|
+
# Similarly we can choose an operating system for the server:
|
65
|
+
puts SoftLayer::VirtualServerOrder.os_reference_code_options(client).inspect
|
66
|
+
server_order.os_reference_code = 'CENTOS_6_64'
|
67
|
+
|
68
|
+
# Finally, in spite of the fact that our server is simple, we want it
|
69
|
+
# to have a blazing fast connection speed. Let's look at the options and choose
|
70
|
+
# the fastest! (it's probably 1 Gbps)
|
71
|
+
server_order.max_port_speed = SoftLayer::VirtualServerOrder.max_port_speed_options(client).max
|
72
|
+
|
73
|
+
# The server order is now complete. This sample will ask it to verify itself with the
|
74
|
+
# SoftLayer ordering system, but a simple change from verify to place_order! would ask
|
75
|
+
# the system to provision the server (and charge it to our account)
|
76
|
+
begin
|
77
|
+
server_order.verify
|
78
|
+
puts "The server order is OK"
|
79
|
+
rescue Exception => e
|
80
|
+
puts "The server order failed verification :-( -- #{e}"
|
81
|
+
end
|
82
|
+
rescue Exception => exception
|
83
|
+
$stderr.puts "An exception occurred while trying to complete the SoftLayer API calls #{exception}"
|
84
|
+
end
|
85
|
+
|