fog-sakuracloud 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c091507bd4319e29aaec68ccec48639442edba9
4
- data.tar.gz: ef1f332eeed7a16ceb330d8eb9510b87d5ece2bb
3
+ metadata.gz: 014fe488d00660395b62a242e215abe51ca05c63
4
+ data.tar.gz: fb076fcce9be47923d125cf7a8bc112c66f397f9
5
5
  SHA512:
6
- metadata.gz: 8edf9a260ef6f5990ade711a07478f3761e6cde29e9cde6a0353777f87627e9e74b994a2960c5de981ff40aaf7d22a9b7538cd30da030f15003dc2d3603ddf35
7
- data.tar.gz: 10dcd3507057780c9959c70e5b4b250f510e3cbad3ce1f684bb7b4c17ae50fb0a1231ab3d3ec59c16c023e88679f2e8a398aaf0757369ce29e66a081dfc4f420
6
+ metadata.gz: ead625df63feec5beb0f5007a6d8ce8afa07583b5889482abb4c2a1352883330ba9396a4f2f59ac24d285f820aab3c791f238fd696054a32b27759f090a1e7e9
7
+ data.tar.gz: 65dd7c88569457e006ed7563360d24a1c9a4faa088dfa2b07f231a186594a11c036b631beb83021916dd71e640781e1046117f574724fc09aa816b164289e202
@@ -1,5 +1,9 @@
1
1
  # Changelog of fog-sakuracloud
2
2
 
3
+ ## v1.3.0
4
+
5
+ - Feature: Manage Cloud DNS
6
+
3
7
  ## v1.2.0
4
8
 
5
9
  - Feature: Manage Interface.
@@ -14,6 +14,10 @@ module Fog
14
14
  autoload :SakuraCloud, File.expand_path('../sakuracloud/volume', __FILE__)
15
15
  end
16
16
 
17
+ module DNS
18
+ autoload :SakuraCloud, File.expand_path('../sakuracloud/dns', __FILE__)
19
+ end
20
+
17
21
  module SakuraCloud
18
22
  extend Fog::Provider
19
23
 
@@ -29,5 +33,6 @@ module Fog
29
33
  service(:volume, 'Volume')
30
34
  service(:network, 'Network')
31
35
  service(:script, 'Script')
36
+ service(:dns, 'DNS')
32
37
  end
33
38
  end
@@ -25,7 +25,6 @@ module Fog
25
25
  request :list_plans
26
26
  request :list_ssh_keys
27
27
  request :list_zones
28
- request :regist_interface_to_server
29
28
 
30
29
  class Real
31
30
  def initialize(options = {})
@@ -0,0 +1,76 @@
1
+ module Fog
2
+ module DNS
3
+ class SakuraCloud < Fog::Service
4
+ requires :sakuracloud_api_token
5
+ requires :sakuracloud_api_token_secret
6
+
7
+ recognizes :sakuracloud_api_url
8
+
9
+ model_path 'fog/sakuracloud/models/dns'
10
+ model :zone
11
+ collection :zones
12
+
13
+ request_path 'fog/sakuracloud/requests/dns'
14
+ request :list_zones
15
+ request :create_zone
16
+ request :delete_zone
17
+ request :modify_zone
18
+
19
+ class Real
20
+ def initialize(options = {})
21
+ @auth_encord = Base64.strict_encode64([
22
+ options[:sakuracloud_api_token],
23
+ options[:sakuracloud_api_token_secret]
24
+ ].join(':'))
25
+ Fog.credentials[:sakuracloud_api_token] = options[:sakuracloud_api_token]
26
+ Fog.credentials[:sakuracloud_api_token_secret] = options[:sakuracloud_api_token_secret]
27
+
28
+ @sakuracloud_api_url = options[:sakuracloud_api_url] || 'https://secure.sakura.ad.jp'
29
+
30
+ @connection = Fog::Core::Connection.new(@sakuracloud_api_url)
31
+ end
32
+
33
+ def request(params)
34
+ response = parse @connection.request(params)
35
+ response
36
+ end
37
+
38
+ private
39
+ def parse(response)
40
+ return response if response.body.empty?
41
+ response.body = Fog::JSON.decode(response.body)
42
+ response
43
+ end
44
+ end
45
+
46
+ class Mock
47
+ def self.data
48
+ @data ||= Hash.new do |hash, key|
49
+ hash[key] = {
50
+ :notes => []
51
+ }
52
+ end
53
+ end
54
+
55
+ def self.reset
56
+ @data = nil
57
+ end
58
+
59
+ def initialize(options={})
60
+ @sakuracloud_api_token = options[:sakuracloud_api_token]
61
+ @sakuracloud_api_token_secret = options[:sakuracloud_api_token_secret]
62
+ end
63
+
64
+ def data
65
+ self.class.data[@sakuracloud_api_token]
66
+ self.class.data[@sakuracloud_api_token_secret]
67
+ end
68
+
69
+ def reset_data
70
+ self.class.data.delete(@sakuracloud_api_token)
71
+ self.class.data.delete(@sakuracloud_api_token_secret)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,49 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module DNS
5
+ class SakuraCloud
6
+ class Zone < Fog::Model
7
+ identity :id, :aliases => 'ID'
8
+ attribute :name, :aliases => 'Name'
9
+ attribute :description, :aliases => 'Description'
10
+ attribute :status, :aliases => 'Status'
11
+ attribute :settings, :aliases => 'Settings'
12
+ attribute :tags, :aliases => 'Tags'
13
+
14
+ ## Reader methods for nested values.
15
+ # Returns value or nil
16
+ def rr_sets
17
+ settings.fetch('DNS', {}).fetch('ResourceRecordSets', []) if settings
18
+ end
19
+
20
+ def zone
21
+ status.fetch('Zone') if status
22
+ end
23
+
24
+ def nameservers
25
+ status.fetch('NS') if status
26
+ end
27
+
28
+ def delete
29
+ service.delete_zone(identity)
30
+ true
31
+ end
32
+ alias_method :destroy, :delete
33
+
34
+ def save
35
+ requires :zone
36
+ if identity
37
+ Fog::Logger.warning("Update DNS Zone #{identity}")
38
+ data = service.modify_zone(@attributes).body["CommonServiceItem"]
39
+ else
40
+ Fog::Logger.warning("Create DNS Zone")
41
+ data = service.create_zone(@attributes).body["CommonServiceItem"]
42
+ end
43
+ merge_attributes(data)
44
+ true
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,27 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/sakuracloud/models/dns/zone'
3
+
4
+ module Fog
5
+ module DNS
6
+ class SakuraCloud
7
+ class Zones < Fog::Collection
8
+ model Fog::DNS::SakuraCloud::Zone
9
+
10
+ def all
11
+ load service.list_zones.body['CommonServiceItems']
12
+ end
13
+
14
+ def get(id)
15
+ all.find { |f| f.id == id }
16
+ rescue Fog::Errors::NotFound
17
+ nil
18
+ end
19
+
20
+ def delete(id)
21
+ service.delete_zone(id)
22
+ true
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+
3
+ module Fog
4
+ module DNS
5
+ class SakuraCloud
6
+ class Real
7
+ def create_zone(options)
8
+ name = options[:name] ? options[:name] : options[:zone]
9
+ body = {
10
+ "CommonServiceItem"=>{
11
+ "Name"=>name,
12
+ "Status"=>{"Zone"=>options[:zone]},
13
+ "Provider"=>{"Class"=>"dns"},
14
+ "Description"=> options[:description],
15
+ "Settings" => {
16
+ "DNS" => {
17
+ "ResourceRecordSets" => options[:rr_sets]
18
+ }
19
+ }
20
+ }
21
+ }
22
+
23
+ request(
24
+ :headers => {
25
+ 'Authorization' => "Basic #{@auth_encord}"
26
+ },
27
+ :expects => 201,
28
+ :method => 'POST',
29
+ :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/commonserviceitem",
30
+ :body => Fog::JSON.encode(body)
31
+ )
32
+ end
33
+ end # Real
34
+
35
+ class Mock
36
+ def create_zone(options)
37
+ response = Excon::Response.new
38
+ response.status = 201
39
+ response.body = {
40
+ }
41
+ response
42
+ end
43
+ end
44
+ end # SakuraCloud
45
+ end # DNS
46
+ end # Fog
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ module Fog
4
+ module DNS
5
+ class SakuraCloud
6
+ class Real
7
+ def delete_zone( id )
8
+ request(
9
+ :headers => {
10
+ 'Authorization' => "Basic #{@auth_encord}"
11
+ },
12
+ :expects => [200],
13
+ :method => 'DELETE',
14
+ :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/commonserviceitem/#{id}"
15
+ )
16
+ end
17
+ end # Real
18
+
19
+ class Mock
20
+ def delete_zone( id )
21
+ response = Excon::Response.new
22
+ response.status = 200
23
+ response.body = {
24
+ }
25
+ response
26
+ end
27
+ end
28
+ end # SakuraCloud
29
+ end # DNS
30
+ end # Fog
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+
3
+ module Fog
4
+ module DNS
5
+ class SakuraCloud
6
+ class Real
7
+ def list_zones(options = {})
8
+ filter = {
9
+ "Filter" => {
10
+ "Provider.Class" => "dns"
11
+ }
12
+ }
13
+ request(
14
+ :headers => {
15
+ 'Authorization' => "Basic #{@auth_encord}"
16
+ },
17
+ :method => 'GET',
18
+ :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/commonserviceitem",
19
+ :query => URI.encode(Fog::JSON.encode(filter))
20
+ )
21
+ end
22
+ end
23
+
24
+ class Mock
25
+ def list_zones(options = {})
26
+ response = Excon::Response.new
27
+ response.status = 200
28
+ response.body = {
29
+ }
30
+ response
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ module Fog
4
+ module DNS
5
+ class SakuraCloud
6
+ class Real
7
+ def modify_zone(options)
8
+ body = {
9
+ "CommonServiceItem"=>{
10
+ "Settings" => options[:settings]
11
+ }
12
+ }
13
+
14
+ request(
15
+ :headers => {
16
+ 'Authorization' => "Basic #{@auth_encord}"
17
+ },
18
+ :expects => 200,
19
+ :method => 'PUT',
20
+ :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/commonserviceitem/#{options[:id]}",
21
+ :body => Fog::JSON.encode(body)
22
+ )
23
+ end
24
+ end # Real
25
+
26
+ class Mock
27
+ def modify_zone(options)
28
+ response = Excon::Response.new
29
+ response.status = 200
30
+ response.body = {
31
+ }
32
+ response
33
+ end
34
+ end
35
+ end # SakuraCloud
36
+ end # DNS
37
+ end # Fog
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Sakuracloud
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-sakuracloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawanoboly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-20 00:00:00.000000000 Z
11
+ date: 2015-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core
@@ -213,6 +213,7 @@ files:
213
213
  - lib/fog/bin/sakuracloud.rb
214
214
  - lib/fog/sakuracloud.rb
215
215
  - lib/fog/sakuracloud/compute.rb
216
+ - lib/fog/sakuracloud/dns.rb
216
217
  - lib/fog/sakuracloud/models/compute/plan.rb
217
218
  - lib/fog/sakuracloud/models/compute/plans.rb
218
219
  - lib/fog/sakuracloud/models/compute/server.rb
@@ -221,6 +222,8 @@ files:
221
222
  - lib/fog/sakuracloud/models/compute/ssh_keys.rb
222
223
  - lib/fog/sakuracloud/models/compute/zone.rb
223
224
  - lib/fog/sakuracloud/models/compute/zones.rb
225
+ - lib/fog/sakuracloud/models/dns/zone.rb
226
+ - lib/fog/sakuracloud/models/dns/zones.rb
224
227
  - lib/fog/sakuracloud/models/network/interface.rb
225
228
  - lib/fog/sakuracloud/models/network/interfaces.rb
226
229
  - lib/fog/sakuracloud/models/network/router.rb
@@ -244,6 +247,10 @@ files:
244
247
  - lib/fog/sakuracloud/requests/compute/list_ssh_keys.rb
245
248
  - lib/fog/sakuracloud/requests/compute/list_zones.rb
246
249
  - lib/fog/sakuracloud/requests/compute/stop_server.rb
250
+ - lib/fog/sakuracloud/requests/dns/create_zone.rb
251
+ - lib/fog/sakuracloud/requests/dns/delete_zone.rb
252
+ - lib/fog/sakuracloud/requests/dns/list_zones.rb
253
+ - lib/fog/sakuracloud/requests/dns/modify_zone.rb
247
254
  - lib/fog/sakuracloud/requests/network/connect_interface_to_switch.rb
248
255
  - lib/fog/sakuracloud/requests/network/create_router.rb
249
256
  - lib/fog/sakuracloud/requests/network/create_switch.rb