fog-softlayer 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGUxNWEyYTgyY2IzNTllYTY0NWVmNmQ3NmExMWI1ZGM5OGQ1MDBiOA==
4
+ NDIyZDM4MDM4OTQzOGJhNmFlNDc1Mzc0ZDY2YTRkYzg1OThiNTlmMQ==
5
5
  data.tar.gz: !binary |-
6
- YzZjNzViYWU2Yzg0OWY1YTc3YTg5MDZjMDYyMDAyZTJhZmJjOTc0MQ==
6
+ ZDE3ZmZlY2FmMTlkMjA0ZjYxZjc1YjI2NzU1ZmNlYmFhYzdhYTdmNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDE1MWMyMTY3OTUyODlhNTRlNzJiYmNlNWUyOWE5NGU5N2JiMGQ2ZTc5ZThm
10
- NjY3OGMwYmYwODI1OGNjMjA5YzE0YTU0YjZkYTY4NGMxNTE4ZjM5MzE1MjM4
11
- YzYwM2EzNTM1YWIwY2FhY2RjMjRjOGZhMzFmNTU5ODIwMjRmYzg=
9
+ YzE4MzU0MzliMWQ0ZWJmMGEyNjg5ZmZjNzlkM2Y0NjlkMzIxODgzZmJjNzQz
10
+ YjJhMjZhZmM4ZjExMjI3ZGUzYjM3N2Q4Y2Q5MWZhNDBmY2Y0NTMwNjM0ZThi
11
+ MmYxOTNmN2Y0MjI4NTcwMWIwOWU0ODQyNjlhNTA2NGJmNGRmNDU=
12
12
  data.tar.gz: !binary |-
13
- NjlmNjNiYzIwMmFiZGRkMDU1MjFhN2Q1YzZhZWVmYTkyZDlmNzMyYTk2YzU2
14
- MzdlMmUxM2NkZmEzOGNmNzk4MWJhY2FiZjYyYWU3MjkyZTE3ZmM2NzE2MzJm
15
- NzQ4MDE1OTBkODQ4NTYwNmNhOTA5YWVjZGYyYzFlMDUxZjIwMDA=
13
+ NDdhY2IyMGRmMDFiNzYwZTkyMTkzNThkMGVjYjc2NGQ1NDBlNjM1NmZlMTg0
14
+ ZWIyMWFhMWQyMTY5NTg3ZDQwZGE4MDM2Yzc0ZjA2MzEwMzExYzFkMmFjNWU2
15
+ OGFlMWM5MTAxZDJmMzgyOTY4OGJlN2Q1YjJkNjdlYjJhNTYzYmY=
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,2 @@
1
+ * Celso Fernandes <fernandes@zertico.com>
2
+ * Matt Eldridge <matt.eldridge@us.ibm.com>
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ### `fog-softlayer` - SoftLayer module for fog (The Ruby cloud services library).
2
- [![Gem Version](https://badge.fury.io/rb/fog-softlayer.png)](http://badge.fury.io/rb/knife-softlayer)
3
- [![Build Status](https://api.travis-ci.org/softlayer/fog-softlayer.svg)](https://travis-ci.org/softlayer/knife-softlayer)
4
- [![Dependency Status](https://gemnasium.com/softlayer/fog-softlayer.svg)](https://gemnasium.com/softlayer/knife-softlayer)
2
+ [![Gem Version](https://badge.fury.io/rb/fog-softlayer.png)](http://badge.fury.io/rb/fog-softlayer)
3
+ [![Build Status](https://api.travis-ci.org/softlayer/fog-softlayer.svg)](https://travis-ci.org/softlayer/fog-softlayer)
4
+ [![Dependency Status](https://gemnasium.com/softlayer/fog-softlayer.svg)](https://gemnasium.com/softlayer/fog-softlayer)
5
5
 
6
6
  This gem is a module for the `fog` gem that allows you to manage resources in
7
7
  the SoftLayer Cloud.
data/examples/dns.md ADDED
@@ -0,0 +1,93 @@
1
+ ### DNS Examples
2
+
3
+ These examples all assume you have `~/.fog` which contains the following
4
+
5
+
6
+ ```yaml
7
+ :softlayer_username: example-username
8
+ :softlayer_api_key: 1a1a1a1a1a1a1a1a1a11a1a1a1a1a1a1a1a1a1
9
+ ```
10
+
11
+ #### Create a connection to SoftLayer DNS Service
12
+
13
+ ```ruby
14
+ require 'fog/softlayer'
15
+ @sl = Fog::DNS[:softlayer]
16
+ ```
17
+
18
+ 1. Create Operations
19
+
20
+ * Create Domain
21
+
22
+ ```ruby
23
+ @domain = @sl.domains.create('yourdomain.com')
24
+ ```
25
+
26
+ * Create Record
27
+
28
+ ```ruby
29
+ record = {
30
+ 'data' => '127.0.0.1',
31
+ 'host' => '@',
32
+ 'type' => 'a'
33
+ }
34
+ @domain.create_record(record)
35
+ ```
36
+
37
+ 1. Read Operations
38
+
39
+ * List all domains
40
+
41
+ ```ruby
42
+ @domains = @sl.domains.all
43
+ @domain = @domains.first
44
+ ```
45
+
46
+ * Get specific domain by id
47
+
48
+ ```ruby
49
+ @domain = @sl.domains.get(123456)
50
+ ```
51
+
52
+ * Get specific domain by name
53
+
54
+ ```ruby
55
+ @domain = @sl.domains.get_by_name('yourdomain.com')
56
+ ```
57
+
58
+ * Get Domains Records
59
+
60
+ ```ruby
61
+ @domain = @sl.domains.get(123456)
62
+ @domain.records
63
+ ```
64
+
65
+ 1. Update Operations
66
+
67
+ After this point we consider you have a Fog::DNS::Softlayer::Domain on @domain variable
68
+
69
+ * Update Record Entry
70
+
71
+ ```ruby
72
+ @domain.records
73
+ @domain.records[3].value = "192.168.0.3"
74
+ @domain.records[3].save
75
+ ```
76
+
77
+ 1. Destroy Operations
78
+
79
+ After this point we consider you have a Fog::DNS::Softlayer::Domain on @domain variable
80
+
81
+ * Destroy Domain
82
+
83
+ ```ruby
84
+ @domain = @sl.domains.get(123456)
85
+ @domain.destroy
86
+ ```
87
+
88
+ * Destroy Record
89
+
90
+ ```ruby
91
+ @domain = @sl.domains.get(123456)
92
+ @domain.records.last.destroy
93
+ ```
data/examples/storage.md CHANGED
@@ -42,7 +42,7 @@ These examples all assume you have `~/.fog` which contains the following
42
42
  ```ruby
43
43
  dir = @sl.directories.get('a-container')
44
44
  # Pass a string.
45
- dir.files.create(:key => 'data.txt', :body => 'The quick brown fox jumps over the lazy dog.")
45
+ dir.files.create(:key => 'data.txt', :body => 'The quick brown fox jumps over the lazy dog.')
46
46
  # From a file.
47
47
  dir.files.create(:key => 'file-data.txt', :body => File.open('/path/to/file-data.txt')
48
48
  ```
@@ -91,6 +91,7 @@ These examples all assume you have `~/.fog` which contains the following
91
91
  ```ruby
92
92
  file = @sl.directories.get('a-container').files.get('data.txt')
93
93
  file.url(Time.now + 300) # url expires in 5 minutes
94
+ # => "https://dal05.objectstorage.softlayer.net:443/v1/AUTH_1a1a1a1a-1a1a-1a1a-1a1a-1a1a1a1a1a1a/a-container/data.txt?temp_url_sig=1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a&temp_url_expires=1401901023"
94
95
  ```
95
96
 
96
97
  1. Delete files/objects from a directory/container.
@@ -104,4 +105,4 @@ These examples all assume you have `~/.fog` which contains the following
104
105
  dir.destroy
105
106
  ```
106
107
 
107
-
108
+
data/lib/fog/softlayer.rb CHANGED
@@ -7,4 +7,5 @@
7
7
  require 'fog'
8
8
  require 'fog/softlayer'
9
9
  require 'fog/softlayer/compute'
10
+ require 'fog/softlayer/dns'
10
11
  require 'fog/softlayer/storage'
@@ -17,6 +17,7 @@ module Fog
17
17
  SL_STORAGE_AUTH_URL = 'objectstorage.softlayer.net/auth/v1.0' unless defined? SL_STORAGE_AUTH_URL
18
18
 
19
19
  service(:compute, 'Compute')
20
+ service(:dns, 'DNS')
20
21
  service(:storage, 'Storage')
21
22
 
22
23
  def self.mock_account_id
@@ -0,0 +1,162 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ require 'fog/softlayer/core'
9
+ require 'fog/softlayer/compute/shared'
10
+
11
+ module Fog
12
+ module DNS
13
+ class Softlayer < Fog::Service
14
+ class MissingRequiredParameter < Fog::Errors::Error; end
15
+
16
+ # Client credentials
17
+ requires :softlayer_username, :softlayer_api_key
18
+
19
+ # Excon connection settings
20
+ recognizes :softlayer_api_url
21
+ recognizes :softlayer_default_domain
22
+
23
+
24
+ model_path 'fog/softlayer/models/dns'
25
+ collection :domains
26
+ model :domain
27
+ collection :records
28
+ model :record
29
+
30
+ request_path 'fog/softlayer/requests/dns'
31
+ request :create_domain
32
+ request :create_record
33
+ request :delete_domain
34
+ request :delete_record
35
+ request :get_domain
36
+ request :get_domain_by_name
37
+ request :get_domains
38
+ request :get_records
39
+ request :update_record
40
+
41
+ # The Mock Service allows you to run a fake instance of the Service
42
+ # which makes no real connections.
43
+ #
44
+ #
45
+ class Mock
46
+ attr_accessor :default_domain
47
+ include Fog::Softlayer::Compute::Shared
48
+
49
+ def initialize(args)
50
+ @softlayer_domains = []
51
+ super(args)
52
+ end
53
+
54
+ end
55
+
56
+ ##
57
+ # Makes real connections to Softlayer.
58
+ #
59
+ class Real
60
+ attr_accessor :default_domain
61
+ include Fog::Softlayer::Compute::Shared
62
+
63
+ # Sends the real request to the real SoftLayer service.
64
+ #
65
+ # @param [String] service
66
+ # ...ayer.com/rest/v3/Softlayer_Service_Name...
67
+ # @param path [String]
68
+ # ...ayer.com/rest/v3/Softlayer_Service_Name/path.json
69
+ # @param [Hash] options
70
+ # @option options [Array<Hash>] :body
71
+ # HTTP request body parameters
72
+ # @option options [String] :softlayer_api_url
73
+ # Override the default (or configured) API endpoint
74
+ # @option options [String] :softlayer_username
75
+ # Email or user identifier for user based authentication
76
+ # @option options [String] :softlayer_api_key
77
+ # Password for user based authentication
78
+ # @return [Excon::Response]
79
+ def request(service, path, options={})
80
+
81
+ # default HTTP method to get if not passed
82
+ http_method = options[:http_method] || :get
83
+ # set the target base url
84
+ @request_url = options[:softlayer_api_url] || Fog::Softlayer::SL_API_URL
85
+ # tack on the username and password
86
+ credentialize_url(@credentials[:username], @credentials[:api_key])
87
+ # set the SoftLayer Service name
88
+ set_sl_service(service)
89
+ # set the request path (known as the "method" in SL docs)
90
+ set_sl_path(path)
91
+ # set the query params if any
92
+
93
+
94
+ # build request params
95
+ params = { :headers => user_agent_header }
96
+ params[:headers]['Content-Type'] = 'application/json'
97
+ params[:expects] = options[:expected] || [200,201]
98
+ params[:body] = Fog::JSON.encode({:parameters => [ options[:body] ]}) unless options[:body].nil?
99
+ params[:query] = options[:query] unless options[:query].nil?
100
+
101
+ # initialize connection object
102
+ @connection = Fog::Core::Connection.new(@request_url, false, params)
103
+
104
+ # send it
105
+ response = @connection.request(:method => http_method)
106
+
107
+ # decode it
108
+ response.body = Fog::JSON.decode(response.body)
109
+ response
110
+ end
111
+
112
+ private
113
+
114
+ def credentialize_url(username, apikey)
115
+ @request_url = "https://#{username}:#{apikey}@#{@request_url}"
116
+ end
117
+
118
+ ##
119
+ # Prepend "SoftLayer_" to the service name and Snake_Camel_Case the string before appending it to the @request_url.
120
+ #
121
+ # On DNS we have the service: SoftLayer_Dns_Domain_ResourceRecord
122
+ # As it does NOT follow any pattern, you can specify
123
+ # :dns_domain_resourceRecord
124
+ # So set_sl_service will NOT change you service name case (just first letters), pay attention
125
+ def set_sl_service(service)
126
+ service = "SoftLayer_" << service.to_s.gsub(/^softlayer_/i, '').split('_').map{|i| i[0].upcase + i[1..-1]}.join('_')
127
+ @request_url += "/#{service}"
128
+ end
129
+
130
+ ##
131
+ # Try to smallCamelCase the path before appending it to the @request_url
132
+ #
133
+ def set_sl_path(path)
134
+ path = path.to_s.underscore.camelize
135
+ @request_url += "/#{path}.json"
136
+ end
137
+
138
+ def user_agent_header
139
+ {"User-Agent" => "Fog SoftLayer Adapter #{Fog::Softlayer::VERSION}"}
140
+ end
141
+
142
+ end
143
+
144
+ end
145
+
146
+ end
147
+ end
148
+
149
+ ## some helpers for some dirty work
150
+ class String
151
+ def camelize
152
+ self.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
153
+ end
154
+
155
+ def underscore
156
+ self.gsub(/::/, '/').
157
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
158
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
159
+ tr("-", "_").
160
+ downcase
161
+ end
162
+ end
@@ -0,0 +1,53 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ require 'fog/core/model'
8
+ require 'fog/softlayer/models/dns/records'
9
+
10
+ module Fog
11
+ module DNS
12
+ class Softlayer
13
+
14
+ class Domain < Fog::Model
15
+
16
+ identity :id, :type => :integer
17
+ attribute :name, :aliases => 'domain'
18
+ attribute :serial, :type => :integer
19
+
20
+ # Times
21
+ attribute :updated_at, :aliases => 'updateDate', :type => :time
22
+
23
+ def initialize(attributes = {})
24
+ super(attributes)
25
+ end
26
+
27
+ def records(reload = false)
28
+ @records = nil if reload
29
+ @records ||= begin
30
+ Fog::DNS::Softlayer::Records.new(
31
+ :domain => self,
32
+ :service => service
33
+ )
34
+ end
35
+ end
36
+
37
+ def create_record(opts = {})
38
+ opts.merge!({:domain_id => self.id, :service => service})
39
+ record = Fog::DNS::Softlayer::Record.new(opts)
40
+ record.save
41
+ records(true)
42
+ record
43
+ end
44
+
45
+ def destroy
46
+ requires :id
47
+ response = service.delete_domain self.id
48
+ response.body
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,57 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ require 'fog/core/collection'
8
+ require 'fog/softlayer/models/compute/server'
9
+
10
+ module Fog
11
+ module DNS
12
+ class Softlayer
13
+
14
+ class Domains < Fog::Collection
15
+
16
+ model Fog::DNS::Softlayer::Domain
17
+
18
+ def all
19
+ data = service.get_domains.body
20
+ load(data)
21
+ end
22
+
23
+ def get(identifier)
24
+ return nil if identifier.nil? || identifier == ""
25
+ response = service.get_domain(identifier)
26
+ data = response.body
27
+ new.merge_attributes(data)
28
+ rescue Excon::Errors::NotFound
29
+ nil
30
+ end
31
+
32
+ def get_by_name(name)
33
+ return nil if name.nil? || name == ""
34
+ response = service.get_domain_by_name(name)
35
+ data = response.body
36
+ return false if data.empty?
37
+ new.merge_attributes(data.first)
38
+ rescue Excon::Errors::NotFound
39
+ nil
40
+ end
41
+
42
+
43
+ def create(name)
44
+ template_object = {
45
+ 'name' => name,
46
+ 'resourceRecords' => {},
47
+ }
48
+ response = service.create_domain(template_object)
49
+ data = response.body
50
+ new.merge_attributes(data)
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,68 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ require 'fog/core/model'
8
+
9
+ module Fog
10
+ module DNS
11
+ class Softlayer
12
+ class Record < Fog::Model
13
+ identity :id
14
+ attribute :domain_id, :aliases => "domainId"
15
+ attribute :name, :aliases => "host"
16
+ attribute :value, :aliases => "data"
17
+ attribute :ttl
18
+ attribute :priority, :aliases => "mxPriority"
19
+ attribute :type
20
+ attribute :expire
21
+ attribute :minimum
22
+ attribute :refresh
23
+ attribute :retry
24
+
25
+ def initialize(attributes={})
26
+ self.domain_id = attributes[:domain_id]
27
+ super(attributes)
28
+ end
29
+
30
+ def destroy
31
+ response = service.delete_record(identity)
32
+ response.body
33
+ end
34
+
35
+ def save
36
+ requires :name, :type, :value, :domain_id
37
+ opts = generate_template
38
+
39
+ # to save or to update, thats the question
40
+ if id.nil?
41
+ data = service.create_record(opts)
42
+ merge_attributes(data.body)
43
+ else
44
+ data = service.update_record(self.id, opts)
45
+ end
46
+ true
47
+ end
48
+
49
+ private
50
+ def generate_template
51
+ template = {}
52
+ template[:host] = self.name
53
+ template[:data] = self.value
54
+ template[:type] = self.type
55
+ template[:domainId] = self.domain_id
56
+
57
+ template[:ttl] = self.ttl if self.ttl
58
+ template[:mxPriority] = self.priority if self.priority
59
+ template[:expire] = self.expire if self.expire
60
+ template[:minimum] = self.minimum if self.minimum
61
+ template[:refresh] = self.refresh if self.refresh
62
+ template[:retry] = self.retry if self.retry
63
+ template
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ require 'fog/core/collection'
8
+ require 'fog/softlayer/models/dns/record'
9
+
10
+ module Fog
11
+ module DNS
12
+ class Softlayer
13
+ class Records < Fog::Collection
14
+ attribute :domain
15
+
16
+ model Fog::DNS::Softlayer::Record
17
+
18
+ def all
19
+ requires :domain
20
+ clear
21
+ data = service.get_records(domain.id).body
22
+ load(data)
23
+ end
24
+
25
+ def new(attributes = {})
26
+ requires :domain
27
+ super({ :domain => domain }.merge!(attributes))
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,79 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ module Fog
8
+ module DNS
9
+ class Softlayer
10
+
11
+ class Mock
12
+ def create_domain(opts)
13
+ response = Excon::Response.new
14
+ updated_at = Time.now
15
+ domain_id = Fog::Mock.random_numbers(7)
16
+ body = {
17
+ :id => domain_id,
18
+ :name => opts["name"],
19
+ :serial => updated_at.strftime("%Y%m%d")+"00",
20
+ :updated_at => updated_at,
21
+ :resourceRecords => [
22
+ {
23
+ "data"=>"ns1."+opts["name"]+".",
24
+ "domainId"=>domain_id,
25
+ "expire"=>604800,
26
+ "host"=>"@",
27
+ "id"=>Fog::Mock.random_numbers(8),
28
+ "minimum"=>3600,
29
+ "mxPriority"=>nil,
30
+ "refresh"=>3600,
31
+ "responsiblePerson"=>"admin."+opts["name"]+".",
32
+ "retry"=>300,
33
+ "ttl"=>86400,
34
+ "type"=>"SOA",
35
+ },
36
+ {
37
+ "data"=>"ns1.softlayer.com.",
38
+ "domainId"=>domain_id,
39
+ "expire"=>nil,
40
+ "host"=>"@",
41
+ "id"=>Fog::Mock.random_numbers(8),
42
+ "minimum"=>nil,
43
+ "mxPriority"=>nil,
44
+ "refresh"=>nil,
45
+ "retry"=>nil,
46
+ "ttl"=>86400,
47
+ "type"=>"NS",
48
+ },
49
+ {
50
+ "data"=>"ns2.softlayer.com.",
51
+ "domainId"=>domain_id,
52
+ "expire"=>nil,
53
+ "host"=>"@",
54
+ "id"=>Fog::Mock.random_numbers(8),
55
+ "minimum"=>nil,
56
+ "mxPriority"=>nil,
57
+ "refresh"=>nil,
58
+ "retry"=>nil,
59
+ "ttl"=>86400,
60
+ "type"=>"NS",
61
+ }
62
+ ]
63
+ }
64
+ response.body = body
65
+ @softlayer_domains << body
66
+ response.status = 200
67
+ response
68
+ end
69
+
70
+ end
71
+
72
+ class Real
73
+ def create_domain(opts)
74
+ request(:dns_domain, :create_object, :body => opts, :http_method => :POST)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ module Fog
8
+ module DNS
9
+ class Softlayer
10
+
11
+ class Mock
12
+ def create_record(opts)
13
+ new_record = {
14
+ "id" => Fog::Mock.random_numbers(8),
15
+ "data" => opts[:data],
16
+ "domainId" => opts[:domainId],
17
+ "host" => opts[:host],
18
+ "type" => opts[:type],
19
+ "minimum" => nil,
20
+ "expire" => nil,
21
+ "mxPriority" => nil,
22
+ "refresh" => nil,
23
+ "responsiblePerson" => nil,
24
+ "retry" => nil,
25
+ "ttl" => nil,
26
+ }
27
+ @softlayer_domains.each do |domain|
28
+ if domain[:id].to_i == opts[:domainId]
29
+ domain[:serial] = domain[:serial].to_i + 1
30
+ domain[:resourceRecords] << new_record
31
+ response = Excon::Response.new
32
+ response.body = new_record
33
+ response.status = 200
34
+ return response
35
+ end
36
+ end
37
+ raise Excon::Errors::NotFound
38
+ end
39
+
40
+ end
41
+
42
+ class Real
43
+ def create_record(opts)
44
+ request(:dns_domain_resourceRecord, :create_object, :body => opts, :http_method => :POST)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ module Fog
8
+ module DNS
9
+ class Softlayer
10
+
11
+ class Mock
12
+ def delete_domain(id)
13
+ @softlayer_domains.each do |domain|
14
+ if domain[:id].to_i == id
15
+ @softlayer_domains.delete(domain)
16
+ response = Excon::Response.new
17
+ response.body = true
18
+ response.status = 200
19
+ return response
20
+ end
21
+ end
22
+ raise Excon::Errors::NotFound
23
+ end
24
+
25
+ end
26
+
27
+ class Real
28
+ def delete_domain(id)
29
+ request(:dns_domain, id.to_s, :http_method => :DELETE)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ module Fog
8
+ module DNS
9
+ class Softlayer
10
+
11
+ class Mock
12
+ def delete_record(id)
13
+ # Get the domain
14
+ @domain = @softlayer_domains.each do |domain|
15
+ domain[:resourceRecords].each do |record|
16
+ if record["id"] == id
17
+ domain[:serial] = domain[:serial] + 1
18
+ domain[:resourceRecords].delete(record)
19
+ end
20
+ end
21
+ end
22
+
23
+ response = Excon::Response.new
24
+ response.body = true
25
+ response.status = 200
26
+ response
27
+ end
28
+
29
+ end
30
+
31
+ class Real
32
+ def delete_record(id)
33
+ request(:dns_domain_resourceRecord, id.to_s, :http_method => :DELETE)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ module Fog
8
+ module DNS
9
+ class Softlayer
10
+
11
+ class Mock
12
+ def get_domain(id)
13
+ @softlayer_domains.each do |domain|
14
+ if domain[:id].to_i == id
15
+ response = Excon::Response.new
16
+ response.body = domain
17
+ response.status = 200
18
+ return response
19
+ end
20
+ end
21
+ raise Excon::Errors::NotFound
22
+ end
23
+
24
+ end
25
+
26
+ class Real
27
+ def get_domain(id)
28
+ request(:dns_domain, id)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ module Fog
8
+ module DNS
9
+ class Softlayer
10
+
11
+ class Mock
12
+ def get_domain_by_name(name)
13
+ @softlayer_domains.each do |domain|
14
+ if domain[:name] == name
15
+ response = Excon::Response.new
16
+ response.body = [ domain ]
17
+ response.status = 200
18
+ return response
19
+ end
20
+ end
21
+ response = Excon::Response.new
22
+ response.body = [ ]
23
+ response.status = 200
24
+ return response
25
+ end
26
+
27
+ end
28
+
29
+ class Real
30
+ def get_domain_by_name(name)
31
+ request(:dns_domain, "getByDomainName/" + URI::encode(name.to_s, "-"))
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ module Fog
8
+ module DNS
9
+ class Softlayer
10
+
11
+ class Mock
12
+ def get_domains
13
+ response = Excon::Response.new
14
+ response.body = @softlayer_domains
15
+ response.status = 200
16
+ return response
17
+ end
18
+
19
+ end
20
+
21
+ class Real
22
+ def get_domains
23
+ request(:account, :get_domains)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ module Fog
8
+ module DNS
9
+ class Softlayer
10
+
11
+ class Mock
12
+ def get_records(domain_id)
13
+ @softlayer_domains.each do |domain|
14
+ if domain[:id].to_i == domain_id
15
+ response = Excon::Response.new
16
+ response.body = domain[:resourceRecords]
17
+ response.status = 200
18
+ return response
19
+ end
20
+ end
21
+ raise Excon::Errors::NotFound
22
+ end
23
+
24
+ end
25
+
26
+ class Real
27
+ def get_records(domain_id)
28
+ request(:dns_domain, domain_id.to_s + '/getResourceRecords')
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ module Fog
8
+ module DNS
9
+ class Softlayer
10
+
11
+ class Mock
12
+ def update_record(record_id, opts)
13
+
14
+ # Get the domain
15
+ @domain = @softlayer_domains.each do |domain|
16
+ if domain[:id].to_i == opts[:domainId]
17
+ domain
18
+ end
19
+ end
20
+
21
+ # Get the record
22
+ @domain.first[:resourceRecords].each do |record|
23
+ if record["id"].to_i == record_id.to_i
24
+ @domain.first[:serial] = (@domain.first[:serial] + 1)
25
+ @record = record
26
+ end
27
+ end
28
+
29
+ # Update the data
30
+ # ps: Separated the update to make easier future refator
31
+ @record["data"] = opts[:data]
32
+ @record["host"] = opts[:host]
33
+ @record["type"] = opts[:type]
34
+
35
+ response = Excon::Response.new
36
+ response.body = @domain
37
+ response.status = 200
38
+ return response
39
+ end
40
+ end
41
+
42
+ class Real
43
+ def update_record(record_id, opts)
44
+ request(:dns_domain_resourceRecord, record_id, :body => opts, :http_method => :PUT)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -6,6 +6,6 @@
6
6
  #
7
7
  module Fog
8
8
  module Softlayer
9
- VERSION = "0.0.8"
9
+ VERSION = "0.0.9"
10
10
  end
11
11
  end
data/tests/helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'simplecov'
2
+ require 'securerandom'
2
3
 
3
4
  if ENV['COVERAGE'] == 'true' && RUBY_VERSION != "1.9.2"
4
5
  require 'coveralls'
@@ -21,6 +22,8 @@ Excon.defaults.merge!(:debug_request => true, :debug_response => true)
21
22
 
22
23
  require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'mock_helper'))
23
24
 
25
+ Fog.mock! if ENV['FOG_MOCK']
26
+
24
27
  # This overrides the default 600 seconds timeout during live test runs
25
28
  if Fog.mocking?
26
29
  FOG_TESTING_TIMEOUT = ENV['FOG_TEST_TIMEOUT'] || 2000
@@ -0,0 +1,48 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ Shindo.tests("Fog::DNS[:softlayer] | Domain model", ["softlayer"]) do
9
+
10
+ tests("success") do
11
+
12
+ @service = Fog::DNS[:softlayer]
13
+
14
+ # Setup
15
+ name = "fog-domain-"+SecureRandom.random_number(36**12).to_s(36).rjust(12, "0") + ".com"
16
+ @domain = @service.domains.create(name)
17
+
18
+ tests("#records") do
19
+ returns(3, "returns 3 default records (SOA / NS1 / NS2)") { @domain.records.count }
20
+ end
21
+
22
+ tests("#create_record") do
23
+ record = {
24
+ 'data' => '127.0.0.1',
25
+ 'host' => '@',
26
+ 'type' => 'a'
27
+ }
28
+ current_serial = @domain.serial
29
+ @domain.create_record(record)
30
+ @domain.records(true)
31
+ @domain.reload
32
+ returns(true, "returns serial increased") { (current_serial.to_i + 1) <= @domain.serial }
33
+ returns(4, "returns default plus one created, total 4 records") { @domain.records.count }
34
+ returns("127.0.0.1", "returns the right value for created record") { @domain.records.last.value }
35
+ returns("@", "returns the right name for created record") { @domain.records.last.name }
36
+ returns("a", "returns the right type for created record") { @domain.records.last.type }
37
+ end
38
+
39
+ tests("#destroy") do
40
+ returns(true, "returns confirmation of domain removal") { @domain.destroy }
41
+ returns(false, "returns no domain with that name") { @service.domains.get_by_name(@domain.name) }
42
+ end
43
+
44
+ # Teardown
45
+ # Not needed, domain was already destroyed
46
+ end
47
+ end
48
+
@@ -0,0 +1,72 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ Shindo.tests("Fog::DNS[:softlayer] | Domains model", ["softlayer"]) do
9
+
10
+ @service = Fog::DNS[:softlayer]
11
+
12
+ tests("success") do
13
+
14
+ tests("#create") do
15
+ name = "fog-domain-"+SecureRandom.random_number(36**12).to_s(36).rjust(12, "0") + ".com"
16
+ @domain = @service.domains.create(name)
17
+ returns(Fog::DNS::Softlayer::Domain) { @service.domains.get(@domain.id).class }
18
+ returns(@domain.name, "returns the object with correct name") { @service.domains.get(@domain.id).name }
19
+ @domain.destroy
20
+ end
21
+
22
+ tests("#all") do
23
+
24
+ # Setup
25
+ # Not made on before block to make test fast
26
+ name1 = "fog-domain1-"+SecureRandom.random_number(36**12).to_s(36).rjust(12, "0") + ".com"
27
+ @domain1 = @service.domains.create(name1)
28
+ name2 = "fog-domain2-"+SecureRandom.random_number(36**12).to_s(36).rjust(12, "0") + ".com"
29
+ @domain2 = @service.domains.create(name2)
30
+ name3 = "fog-domain3-"+SecureRandom.random_number(36**12).to_s(36).rjust(12, "0") + ".com"
31
+ @domain3 = @service.domains.create(name3)
32
+
33
+ # Tests if we get the 3 domains we created
34
+ @domains = @service.domains.all
35
+ @domains.each do |domain|
36
+ returns(Fog::DNS::Softlayer::Domain, "returns a "+domain.name) { domain.class }
37
+ end
38
+
39
+ # Check ifs domains we created are included
40
+ domains_names = @domains.map { |domain| domain.name }
41
+ returns(true, "contains domain 1 with name "+@domain1.name) { domains_names.include? @domain1.name }
42
+ returns(true, "contains domain 2 with name "+@domain2.name) { domains_names.include? @domain2.name }
43
+ returns(true, "contains domain 3 with name "+@domain3.name) { domains_names.include? @domain3.name }
44
+
45
+ # Made this way so test pass even theres other domains on account
46
+ returns(true, "returns at least 3 domains") { @domains.count >= 3 }
47
+
48
+ # Teardown
49
+ # Do not leave test domains on my account
50
+ @domain1.destroy
51
+ @domain2.destroy
52
+ @domain3.destroy
53
+ end
54
+
55
+ name = "fog-domain-"+SecureRandom.random_number(36**12).to_s(36).rjust(12, "0") + ".com"
56
+ @domain = @service.domains.create(name)
57
+
58
+ tests("#get") do
59
+ returns(Fog::DNS::Softlayer::Domain) { @service.domains.get(@domain.id).class }
60
+ returns(@domain.name, "returns the object with correct name") { @service.domains.get(@domain.id).name }
61
+ end
62
+
63
+ tests("#get_by_name") do
64
+ returns(Fog::DNS::Softlayer::Domain) { @service.domains.get_by_name(@domain.name).class }
65
+ returns(@domain.name, "returns the object with correct name") { @service.domains.get_by_name(@domain.name).name }
66
+ end
67
+
68
+ @domain.destroy
69
+
70
+ end
71
+ end
72
+
@@ -0,0 +1,55 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ Shindo.tests("Fog::DNS[:softlayer] | Record model", ["softlayer"]) do
9
+
10
+ @service = Fog::DNS[:softlayer]
11
+
12
+ tests("success") do
13
+
14
+ # Setup
15
+ name = "fog-domain-"+SecureRandom.random_number(36**12).to_s(36).rjust(12, "0") + ".com"
16
+ @domain = @service.domains.create(name)
17
+
18
+ tests("#save") do
19
+ record = {
20
+ 'data' => '127.0.0.1',
21
+ 'host' => '@',
22
+ 'type' => 'a'
23
+ }
24
+ current_serial = @domain.serial
25
+ @domain.create_record(record)
26
+ @domain.reload
27
+ @domain.records(true)
28
+ returns(4, "returns default plus one created, total 4 records") { @domain.records.count }
29
+ returns(true, "returns serial increased") { (current_serial + 1) <= @domain.serial }
30
+ returns("127.0.0.1", "returns the right value for created record") { @domain.records.last.value }
31
+ @domain.records.last.value = "192.168.0.1"
32
+ current_serial = @domain.serial
33
+ @domain.records.last.save
34
+ @domain.records(true)
35
+ @domain.reload
36
+ returns(4, "returns 4 records (no duplicated)") { @domain.records.count }
37
+ returns("192.168.0.1", "returns the right value for updated record") { @domain.records.last.value }
38
+ returns(true, "returns serial increased") { (current_serial + 1) <= @domain.serial }
39
+ end
40
+
41
+ tests("#destroy") do
42
+ current_serial = @domain.serial
43
+ @domain.records.last.destroy
44
+ @domain.records(true)
45
+ @domain.reload
46
+ returns(true, "returns serial increased") { (current_serial + 1) <= @domain.serial }
47
+ returns(3, "returns default records for domain (last was deleted)") { @domain.records.count }
48
+ end
49
+
50
+ # Teardown
51
+ @domain.destroy
52
+
53
+ end
54
+ end
55
+
@@ -0,0 +1,27 @@
1
+ #
2
+ # Author:: Celso Fernandes (<fernandes@zertico.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ Shindo.tests("Fog::DNS[:softlayer] | Records model", ["softlayer"]) do
9
+
10
+ @service = Fog::DNS[:softlayer]
11
+
12
+ tests("success") do
13
+
14
+ # Setup
15
+ name = "fog-domain-"+SecureRandom.random_number(36**12).to_s(36).rjust(12, "0") + ".com"
16
+ @domain = @service.domains.create(name)
17
+
18
+ tests("#all") do
19
+ returns(3, "returns default records for domain") { @domain.records.count }
20
+ end
21
+
22
+ # Teardown
23
+ @domain.destroy
24
+
25
+ end
26
+ end
27
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-softlayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Eldridge
@@ -223,6 +223,7 @@ files:
223
223
  - .travis.yml
224
224
  - CHANGELOG.md
225
225
  - CONTRIBUTING.md
226
+ - CONTRIBUTORS.md
226
227
  - Gemfile
227
228
  - LICENSE.txt
228
229
  - README.md
@@ -232,6 +233,7 @@ files:
232
233
  - docs/fog-softlayer-CCLA.pdf
233
234
  - docs/fog-softlayer-CLA.pdf
234
235
  - examples/compute.md
236
+ - examples/dns.md
235
237
  - examples/storage.md
236
238
  - fog-softlayer.gemspec
237
239
  - gemfiles/Gemfile-edge
@@ -241,12 +243,17 @@ files:
241
243
  - lib/fog/softlayer/compute.rb
242
244
  - lib/fog/softlayer/compute/shared.rb
243
245
  - lib/fog/softlayer/core.rb
246
+ - lib/fog/softlayer/dns.rb
244
247
  - lib/fog/softlayer/models/compute/flavor.rb
245
248
  - lib/fog/softlayer/models/compute/flavors.rb
246
249
  - lib/fog/softlayer/models/compute/image.rb
247
250
  - lib/fog/softlayer/models/compute/images.rb
248
251
  - lib/fog/softlayer/models/compute/server.rb
249
252
  - lib/fog/softlayer/models/compute/servers.rb
253
+ - lib/fog/softlayer/models/dns/domain.rb
254
+ - lib/fog/softlayer/models/dns/domains.rb
255
+ - lib/fog/softlayer/models/dns/record.rb
256
+ - lib/fog/softlayer/models/dns/records.rb
250
257
  - lib/fog/softlayer/models/storage/directories.rb
251
258
  - lib/fog/softlayer/models/storage/directory.rb
252
259
  - lib/fog/softlayer/models/storage/file.rb
@@ -260,6 +267,15 @@ files:
260
267
  - lib/fog/softlayer/requests/compute/get_bare_metal_servers.rb
261
268
  - lib/fog/softlayer/requests/compute/get_vm.rb
262
269
  - lib/fog/softlayer/requests/compute/get_vms.rb
270
+ - lib/fog/softlayer/requests/dns/create_domain.rb
271
+ - lib/fog/softlayer/requests/dns/create_record.rb
272
+ - lib/fog/softlayer/requests/dns/delete_domain.rb
273
+ - lib/fog/softlayer/requests/dns/delete_record.rb
274
+ - lib/fog/softlayer/requests/dns/get_domain.rb
275
+ - lib/fog/softlayer/requests/dns/get_domain_by_name.rb
276
+ - lib/fog/softlayer/requests/dns/get_domains.rb
277
+ - lib/fog/softlayer/requests/dns/get_records.rb
278
+ - lib/fog/softlayer/requests/dns/update_record.rb
263
279
  - lib/fog/softlayer/requests/storage/copy_object.rb
264
280
  - lib/fog/softlayer/requests/storage/delete_container.rb
265
281
  - lib/fog/softlayer/requests/storage/delete_multiple_objects.rb
@@ -304,6 +320,10 @@ files:
304
320
  - tests/softlayer/models/compute/flavor_tests.rb
305
321
  - tests/softlayer/models/compute/image_tests.rb
306
322
  - tests/softlayer/models/compute/server_tests.rb
323
+ - tests/softlayer/models/dns/domain_tests.rb
324
+ - tests/softlayer/models/dns/domains_tests.rb
325
+ - tests/softlayer/models/dns/record_tests.rb
326
+ - tests/softlayer/models/dns/records_tests.rb
307
327
  - tests/softlayer/models/storage/directory_tests.rb
308
328
  - tests/softlayer/models/storage/file_tests.rb
309
329
  - tests/softlayer/requests/compute/bmc_tests.rb