fog-sakuracloud 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +1 -1
  3. data/.travis.yml +2 -0
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile.edge +5 -0
  6. data/README.md +4 -1
  7. data/Rakefile +0 -1
  8. data/lib/fog/bin/sakuracloud.rb +8 -3
  9. data/lib/fog/sakuracloud.rb +2 -0
  10. data/lib/fog/sakuracloud/models/compute/server.rb +1 -1
  11. data/lib/fog/sakuracloud/models/compute/servers.rb +2 -1
  12. data/lib/fog/sakuracloud/models/network/router.rb +45 -0
  13. data/lib/fog/sakuracloud/models/network/routers.rb +27 -0
  14. data/lib/fog/sakuracloud/models/network/switch.rb +35 -0
  15. data/lib/fog/sakuracloud/models/network/switches.rb +27 -0
  16. data/lib/fog/sakuracloud/network.rb +83 -0
  17. data/lib/fog/sakuracloud/requests/compute/create_server.rb +16 -5
  18. data/lib/fog/sakuracloud/requests/network/create_router.rb +41 -0
  19. data/lib/fog/sakuracloud/requests/network/create_switch.rb +37 -0
  20. data/lib/fog/sakuracloud/requests/network/delete_router.rb +30 -0
  21. data/lib/fog/sakuracloud/requests/network/delete_switch.rb +30 -0
  22. data/lib/fog/sakuracloud/requests/network/list_routers.rb +39 -0
  23. data/lib/fog/sakuracloud/requests/network/list_switches.rb +74 -0
  24. data/lib/fog/sakuracloud/version.rb +1 -1
  25. data/tests/helper.rb +15 -0
  26. data/tests/sakuracloud/requests/compute/plans_tests.rb +1 -1
  27. data/tests/sakuracloud/requests/compute/servers_tests.rb +2 -2
  28. data/tests/sakuracloud/requests/compute/ssh_keys_tests.rb +1 -1
  29. data/tests/sakuracloud/requests/compute/zones_tests.rb +1 -1
  30. data/tests/sakuracloud/requests/network/routers_tests.rb +52 -0
  31. data/tests/sakuracloud/requests/network/switches_tests.rb +46 -0
  32. data/tests/sakuracloud/requests/volume/archives_tests.rb +1 -1
  33. data/tests/sakuracloud/requests/volume/disks_tests.rb +2 -2
  34. data/tests/sakuracloud/requests/volume/plans_tests.rb +1 -1
  35. metadata +16 -3
  36. data/tests/sakuracloud/helper.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4ca4b284c86d687ba0fd58a9cde3cc139756975
4
- data.tar.gz: 643b55776babe15ae42a98eb9e0ed110a55edf8f
3
+ metadata.gz: ed03013c914dcb9864ddd15863a8ea6ff53bcae8
4
+ data.tar.gz: df5058d91da52223655eeb3a7a144441a0c4b3b0
5
5
  SHA512:
6
- metadata.gz: a504046c33349ca9b072d2e1cb4c99b123c484d83d95dad8249f383ae7d6de4684f4929d64b976d57aea4a68e7fd6f64b481325bdbc8025ff24fff67a0669aed
7
- data.tar.gz: 7a23c5ec208e4f75e61babd6d2d809bc2543c5b04d336281fbb2adf5d5854a8d79361d358d9f4188e8d17519db3c350dc745c91746ed880ad26be429a44b9da8
6
+ metadata.gz: 1d5e6e195d81ef2f071fe2e840580fab2b89add0f19954f5f68f37882364e39309bfddafbda62ab6517d444e683f0fc539bc4948c8568814dd2a885c86571b48
7
+ data.tar.gz: a16f37c56c3e38e89c205495f43f518f114be8e7f3d19bebda581fff2694b46984d09486c2b444b6af87c22a113126c55e7ecd89d1287b5dfcaa2dea6b652be8
data/.gitmodules CHANGED
@@ -1,3 +1,3 @@
1
1
  [submodule "fog"]
2
2
  path = fog
3
- url = https://github.com/fog/fog.git
3
+ url = https://github.com/higanworks/fog.git
data/.travis.yml CHANGED
@@ -7,3 +7,5 @@ rvm:
7
7
  - 2.1.1
8
8
  - 2.0.0
9
9
  - 1.9.3
10
+ gemfile:
11
+ - Gemfile.edge
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog of fog-sakuracloud
2
2
 
3
+ ## v0.1.0
4
+
5
+ - Add: Network resources
6
+ - switch
7
+ - router
8
+ - API change: create server requires options type.
9
+
3
10
  ## v0.0.4
4
11
 
5
12
  - move lib/fog/bin/sakuracloud.rb from fog.
data/Gemfile.edge ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fog-sakuracloud.gemspec
4
+ gemspec
5
+ gem 'fog', :path => './fog'
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Fog::Sakuracloud
2
2
 
3
- [![Build Status](https://travis-ci.org/higanworks/fog-sakuracloud.svg?branch=master)](https://travis-ci.org/higanworks/fog-sakuracloud)
3
+ [![Gem Version](https://badge.fury.io/rb/fog-sakuracloud.svg)](http://badge.fury.io/rb/fog-sakuracloud)
4
+ [![Build Status](https://travis-ci.org/fog/fog-sakuracloud.svg?branch=master)](https://travis-ci.org/fog/fog-sakuracloud)
5
+ [![Stories in Ready](https://badge.waffle.io/fog/fog-sakuracloud.svg?label=ready&title=Ready)](http://waffle.io/fog/fog-sakuracloud)
6
+ [![Stories in Progress](https://badge.waffle.io/fog/fog-sakuracloud.svg?label=In%20Progress&title=In%20Progress')](http://waffle.io/fog/fog-sakuracloud)
4
7
 
5
8
  This gem is a module for the fog gem that allows you to manage resources in the Sakura no Cloud.
6
9
 
data/Rakefile CHANGED
@@ -6,7 +6,6 @@ require 'rubygems'
6
6
  require 'rubygems/package_task'
7
7
  require 'yard'
8
8
  require 'fog'
9
- # require File.dirname(__FILE__) + '/fog/lib/fog'
10
9
 
11
10
  #############################################################################
12
11
  #
@@ -6,6 +6,8 @@ class SakuraCloud < Fog::Bin
6
6
  Fog::Compute::SakuraCloud
7
7
  when :volume
8
8
  Fog::Volume::SakuraCloud
9
+ when :network
10
+ Fog::Network::SakuraCloud
9
11
  else
10
12
  raise ArgumentError, "Unrecognized service: #{key}"
11
13
  end
@@ -15,11 +17,14 @@ class SakuraCloud < Fog::Bin
15
17
  @@connections ||= Hash.new do |hash, key|
16
18
  hash[key] = case key
17
19
  when :compute
18
- Fog::Logger.warning("SakuraCloud[:compute] is not recommended, use Compute[:sakuracloud] for portability")
20
+ Fog::Logger.warning("SakuraCloud[:compute] is not recommended, use Fog::Compute[:sakuracloud] for portability")
19
21
  Fog::Compute.new(:provider => 'SakuraCloud')
20
22
  when :volume
21
- Fog::Logger.warning("SakuraCloud[:compute] is not recommended, use Compute[:SakuraCloud] for portability")
22
- Fog::Compute.new(:provider => 'SakuraCloud')
23
+ Fog::Logger.warning("SakuraCloud[:volume] is not recommended, use Fog::Volume[:sakuracloud] for portability")
24
+ Fog::Volume.new(:provider => 'SakuraCloud')
25
+ when :network
26
+ Fog::Logger.warning("SakuraCloud[:network] is not recommended, use Fog::Network[:sakuracloud] for portability")
27
+ Fog::Network.new(:provider => 'SakuraCloud')
23
28
  else
24
29
  raise ArgumentError, "Unrecognized service: #{key.inspect}"
25
30
  end
@@ -1,6 +1,7 @@
1
1
  require 'fog/core'
2
2
  require 'fog/sakuracloud/compute'
3
3
  require 'fog/sakuracloud/volume'
4
+ require 'fog/sakuracloud/network'
4
5
 
5
6
  module Fog
6
7
  module SakuraCloud
@@ -12,5 +13,6 @@ module Fog
12
13
 
13
14
  service(:compute, 'Compute')
14
15
  service(:volume, 'Volume')
16
+ service(:network, 'Network')
15
17
  end
16
18
  end
@@ -13,7 +13,7 @@ module Fog
13
13
 
14
14
  def save
15
15
  requires :name, :server_plan
16
- data = service.create_server(@attributes[:name], @attributes[:server_plan]).body["Server"]
16
+ data = service.create_server(@attributes).body["Server"]
17
17
  merge_attributes(data)
18
18
  true
19
19
  end
@@ -20,7 +20,8 @@ module Fog
20
20
  def create(options = {})
21
21
  user = options[:user] || 'root'
22
22
  Fog::Logger.warning("Create Server")
23
- data = service.create_server(Fog::UUID.uuid, options[:serverplan]).body["Server"]
23
+ name = options[:name] ? options[:name] : Fog::UUID.uuid
24
+ data = service.create_server(options).body["Server"]
24
25
  server = service.servers.new
25
26
  server.merge_attributes(data)
26
27
 
@@ -0,0 +1,45 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Network
5
+ class SakuraCloud
6
+ class Router < Fog::Model
7
+ identity :id, :aliases => 'ID'
8
+ attribute :name, :aliases => 'Name'
9
+ attribute :description, :aliases => 'Description'
10
+ attribute :server_count, :aliases => 'ServerCount'
11
+ attribute :appliance_count, :aliases => 'ApplianceCount'
12
+ attribute :subnets, :aliases => 'Subnets'
13
+ attribute :ipv6nets, :aliases => 'IPv6Nets'
14
+ attribute :internet, :aliases => 'Internet'
15
+ attribute :bridge, :aliases => 'Bridge'
16
+ attribute :networkmasklen
17
+
18
+
19
+ def delete
20
+ service.delete_router(identity)
21
+ true
22
+ end
23
+ alias_method :destroy, :delete
24
+
25
+ def save
26
+ requires :name, :networkmasklen
27
+ Fog::Logger.warning("Create Router with public subnet")
28
+ data = service.create_router(@attributes).body["Internet"]
29
+ Fog::Logger.warning("Waiting available new router...")
30
+ new_data = router_available?(service, data["ID"])
31
+ merge_attributes(new_data)
32
+ true
33
+ end
34
+
35
+ def router_available?(network, router_id)
36
+ until network.switches.find {|r| r.internet != nil && r.internet["ID"] == router_id}
37
+ print '.'
38
+ sleep 2
39
+ end
40
+ ::JSON.parse((network.switches.find {|r| r.internet != nil && r.internet["ID"] == router_id}).to_json)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/sakuracloud/models/network/router'
3
+
4
+ module Fog
5
+ module Network
6
+ class SakuraCloud
7
+ class Routers < Fog::Collection
8
+ model Fog::Network::SakuraCloud::Router
9
+
10
+ def all
11
+ load service.list_routers.body['Internet']
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_router(id)
22
+ true
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Network
5
+ class SakuraCloud
6
+ class Switch < Fog::Model
7
+ identity :id, :aliases => 'ID'
8
+ attribute :name, :aliases => 'Name'
9
+ attribute :description, :aliases => 'Description'
10
+ attribute :server_count, :aliases => 'ServerCount'
11
+ attribute :appliance_count, :aliases => 'ApplianceCount'
12
+ attribute :subnets, :aliases => 'Subnets'
13
+ attribute :ipv6nets, :aliases => 'IPv6Nets'
14
+ attribute :internet, :aliases => 'Internet'
15
+ attribute :bridge, :aliases => 'Bridge'
16
+
17
+
18
+ def delete
19
+ service.delete_switch(identity)
20
+ true
21
+ end
22
+ alias_method :destroy, :delete
23
+
24
+ def save
25
+ requires :name
26
+ Fog::Logger.warning("Create Switch")
27
+ data = service.create_switch(@attributes).body["Switch"]
28
+ merge_attributes(data)
29
+ true
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/sakuracloud/models/network/switch'
3
+
4
+ module Fog
5
+ module Network
6
+ class SakuraCloud
7
+ class Switches < Fog::Collection
8
+ model Fog::Network::SakuraCloud::Switch
9
+
10
+ def all
11
+ load service.list_switches.body['Switches']
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_switch(id)
22
+ true
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,83 @@
1
+ require 'fog/sakuracloud'
2
+ require 'fog/network'
3
+
4
+ module Fog
5
+ module Network
6
+ class SakuraCloud < Fog::Service
7
+ requires :sakuracloud_api_token
8
+ requires :sakuracloud_api_token_secret
9
+
10
+ recognizes :sakuracloud_api_url
11
+
12
+ model_path 'fog/sakuracloud/models/network'
13
+ model :router
14
+ collection :routers
15
+ model :switch
16
+ collection :switches
17
+
18
+ request_path 'fog/sakuracloud/requests/network'
19
+ request :list_routers
20
+ request :create_router
21
+ request :delete_router
22
+ request :list_switches
23
+ request :create_switch
24
+ request :delete_switch
25
+
26
+ class Real
27
+ def initialize(options = {})
28
+ @auth_encord = Base64.strict_encode64([
29
+ options[:sakuracloud_api_token],
30
+ options[:sakuracloud_api_token_secret]
31
+ ].join(':'))
32
+ Fog.credentials[:sakuracloud_api_token] = options[:sakuracloud_api_token]
33
+ Fog.credentials[:sakuracloud_api_token_secret] = options[:sakuracloud_api_token_secret]
34
+
35
+ @sakuracloud_api_url = options[:sakuracloud_api_url] || 'https://secure.sakura.ad.jp'
36
+
37
+ @connection = Fog::Core::Connection.new(@sakuracloud_api_url)
38
+ end
39
+
40
+ def request(params)
41
+ response = parse @connection.request(params)
42
+ response
43
+ end
44
+
45
+ private
46
+ def parse(response)
47
+ return response if response.body.empty?
48
+ response.body = Fog::JSON.decode(response.body)
49
+ response
50
+ end
51
+ end
52
+
53
+ class Mock
54
+ def self.data
55
+ @data ||= Hash.new do |hash, key|
56
+ hash[key] = {
57
+ :routers => []
58
+ }
59
+ end
60
+ end
61
+
62
+ def self.reset
63
+ @data = nil
64
+ end
65
+
66
+ def initialize(options={})
67
+ @sakuracloud_api_token = options[:sakuracloud_api_token]
68
+ @sakuracloud_api_token_secret = options[:sakuracloud_api_token_secret]
69
+ end
70
+
71
+ def data
72
+ self.class.data[@sakuracloud_api_token]
73
+ self.class.data[@sakuracloud_api_token_secret]
74
+ end
75
+
76
+ def reset_data
77
+ self.class.data.delete(@sakuracloud_api_token)
78
+ self.class.data.delete(@sakuracloud_api_token_secret)
79
+ end
80
+ end
81
+ end #SakuraCloud
82
+ end #Network
83
+ end
@@ -4,14 +4,25 @@ module Fog
4
4
  module Compute
5
5
  class SakuraCloud
6
6
  class Real
7
- def create_server( name, serverplan )
7
+ def create_server(options)
8
+ if options[:switch]
9
+ switchs = options[:switch].split(',')
10
+ connectedswitches = switchs.map do |sw_id|
11
+ {
12
+ "ID" => sw_id
13
+ }
14
+ end
15
+ else
16
+ connectedswitches = [{"Scope"=>"shared", "BandWidthMbps"=>100}]
17
+ end
18
+
8
19
  body = {
9
20
  "Server" => {
10
- "Name" => name,
21
+ "Name" => options[:name],
11
22
  "ServerPlan" => {
12
- "ID" => serverplan.to_i
23
+ "ID" => options[:serverplan].to_i
13
24
  },
14
- "ConnectedSwitches"=>[{"Scope"=>"shared", "BandWidthMbps"=>100}]
25
+ "ConnectedSwitches" => connectedswitches
15
26
  }
16
27
  }
17
28
 
@@ -28,7 +39,7 @@ module Fog
28
39
  end # Real
29
40
 
30
41
  class Mock
31
- def create_server( name, serverplan )
42
+ def create_server(options)
32
43
  response = Excon::Response.new
33
44
  response.status = 201
34
45
  response.body = {
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+
3
+ module Fog
4
+ module Network
5
+ class SakuraCloud
6
+ class Real
7
+ def create_router(options)
8
+ bandwidthmbps = options[:bandwidthmbps] ? options[:bandwidthmbps].to_i : 100
9
+
10
+ body = {
11
+ "Internet" => {
12
+ "Name" => options[:name],
13
+ "NetworkMaskLen"=> options[:networkmasklen].to_i,
14
+ "BandWidthMbps"=> bandwidthmbps
15
+ }
16
+ }
17
+
18
+ request(
19
+ :headers => {
20
+ 'Authorization' => "Basic #{@auth_encord}"
21
+ },
22
+ :expects => 202,
23
+ :method => 'POST',
24
+ :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/internet",
25
+ :body => Fog::JSON.encode(body)
26
+ )
27
+ end
28
+ end # Real
29
+
30
+ class Mock
31
+ def create_router(options)
32
+ response = Excon::Response.new
33
+ response.status = 202
34
+ response.body = {
35
+ }
36
+ response
37
+ end
38
+ end
39
+ end # SakuraCloud
40
+ end # Network
41
+ end # Fog
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ module Fog
4
+ module Network
5
+ class SakuraCloud
6
+ class Real
7
+ def create_switch(options)
8
+ body = {
9
+ "Switch" => {
10
+ "Name" => options[:name]
11
+ }
12
+ }
13
+
14
+ request(
15
+ :headers => {
16
+ 'Authorization' => "Basic #{@auth_encord}"
17
+ },
18
+ :expects => 201,
19
+ :method => 'POST',
20
+ :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/switch",
21
+ :body => Fog::JSON.encode(body)
22
+ )
23
+ end
24
+ end # Real
25
+
26
+ class Mock
27
+ def create_switch(options)
28
+ response = Excon::Response.new
29
+ response.status = 201
30
+ response.body = {
31
+ }
32
+ response
33
+ end
34
+ end
35
+ end # SakuraCloud
36
+ end # Network
37
+ end # Fog
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ module Fog
4
+ module Network
5
+ class SakuraCloud
6
+ class Real
7
+ def delete_router( id )
8
+ request(
9
+ :headers => {
10
+ 'Authorization' => "Basic #{@auth_encord}"
11
+ },
12
+ :expects => [200],
13
+ :method => 'DELETE',
14
+ :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/internet/#{id}"
15
+ )
16
+ end
17
+ end # Real
18
+
19
+ class Mock
20
+ def delete_router( 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 # Network
30
+ end # Fog
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ module Fog
4
+ module Network
5
+ class SakuraCloud
6
+ class Real
7
+ def delete_switch( id )
8
+ request(
9
+ :headers => {
10
+ 'Authorization' => "Basic #{@auth_encord}"
11
+ },
12
+ :expects => [200],
13
+ :method => 'DELETE',
14
+ :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/switch/#{id}"
15
+ )
16
+ end
17
+ end # Real
18
+
19
+ class Mock
20
+ def delete_switch( 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 # Network
30
+ end # Fog
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ module Fog
4
+ module Network
5
+ class SakuraCloud
6
+ class Real
7
+ def list_routers(options = {})
8
+ request(
9
+ :headers => {
10
+ 'Authorization' => "Basic #{@auth_encord}"
11
+ },
12
+ :method => 'GET',
13
+ :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/internet"
14
+ )
15
+ end
16
+ end
17
+
18
+ class Mock
19
+ def list_routers(options = {})
20
+ response = Excon::Response.new
21
+ response.status = 200
22
+ response.body = {
23
+ "Internet"=>[
24
+ {"Index"=>0,
25
+ "ID"=>"112600707538",
26
+ "Switch"=>{
27
+ "ID"=>"112600707539",
28
+ "Name"=>"router2"
29
+ }
30
+ }
31
+ ],
32
+ "is_ok"=>true
33
+ }
34
+ response
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,74 @@
1
+ # coding: utf-8
2
+
3
+ module Fog
4
+ module Network
5
+ class SakuraCloud
6
+ class Real
7
+ def list_switches(options = {})
8
+ request(
9
+ :headers => {
10
+ 'Authorization' => "Basic #{@auth_encord}"
11
+ },
12
+ :method => 'GET',
13
+ :path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/switch"
14
+ )
15
+ end
16
+ end
17
+
18
+ class Mock
19
+ def list_switches(options = {})
20
+ response = Excon::Response.new
21
+ response.status = 200
22
+ response.body = {
23
+ "Switches"=>
24
+ [{"Index"=>0,
25
+ "ID"=>"112600703732",
26
+ "Name"=>"foobar1",
27
+ "Description"=>"",
28
+ "ServerCount"=>0,
29
+ "ApplianceCount"=>0,
30
+ "HybridConnection"=>nil,
31
+ "ServiceClass"=>"cloud/switch/default",
32
+ "CreatedAt"=>"2014-09-05T16:35:41+09:00",
33
+ "Subnets"=>
34
+ [{"ID"=>nil,
35
+ "NetworkAddress"=>nil,
36
+ "NetworkMaskLen"=>nil,
37
+ "DefaultRoute"=>nil,
38
+ "NextHop"=>nil,
39
+ "StaticRoute"=>nil,
40
+ "ServiceClass"=>nil,
41
+ "IPAddresses"=>{"Min"=>nil, "Max"=>nil},
42
+ "Internet"=>{"ID"=>nil, "Name"=>nil, "BandWidthMbps"=>nil, "ServiceClass"=>nil}}],
43
+ "IPv6Nets"=>[],
44
+ "Internet"=>nil,
45
+ "Bridge"=>nil},
46
+ {"Index"=>1,
47
+ "ID"=>"112600703734",
48
+ "Name"=>"foobar2",
49
+ "Description"=>"",
50
+ "ServerCount"=>1,
51
+ "ApplianceCount"=>0,
52
+ "HybridConnection"=>nil,
53
+ "ServiceClass"=>"cloud/switch/default",
54
+ "CreatedAt"=>"2014-09-05T16:36:13+09:00",
55
+ "Subnets"=>
56
+ [{"ID"=>1036,
57
+ "NetworkAddress"=>"133.242.241.240",
58
+ "NetworkMaskLen"=>28,
59
+ "DefaultRoute"=>"133.242.241.241",
60
+ "NextHop"=>nil,
61
+ "StaticRoute"=>nil,
62
+ "ServiceClass"=>"cloud/global-ipaddress-v4/28",
63
+ "IPAddresses"=>{"Min"=>"133.242.241.244", "Max"=>"133.242.241.254"},
64
+ "Internet"=>{"ID"=>"112600703733", "Name"=>"hogehoge2", "BandWidthMbps"=>100, "ServiceClass"=>"cloud/internet/router/100m"}}],
65
+ "IPv6Nets"=>[],
66
+ "Internet"=>{"ID"=>"112600703733", "Name"=>"hogehoge2", "BandWidthMbps"=>100, "Scope"=>"user", "ServiceClass"=>"cloud/internet/router/100m"},
67
+ "Bridge"=>nil}]
68
+ }
69
+ response
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Sakuracloud
3
- VERSION = "0.0.4"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
data/tests/helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ ## Initialize credentials
2
+ ENV['FOG_RC'] = ENV['FOG_RC'] || File.expand_path('../.fog', __FILE__)
3
+
1
4
  ## From fog-core
2
5
  require 'fog/test_helpers/formats_helper'
3
6
 
@@ -6,3 +9,15 @@ require File.expand_path('../../fog/tests/helper', __FILE__)
6
9
  helpers = Dir.glob(File.expand_path('../../', __FILE__) + '/fog/tests/helpers/**/*.rb')
7
10
  helpers.map {|h| load h}
8
11
 
12
+ ## SakuraCloud Helpers
13
+ def sakuracloud_volume_service
14
+ Fog::Volume[:sakuracloud]
15
+ end
16
+
17
+ def sakuracloud_compute_service
18
+ Fog::Compute[:sakuracloud]
19
+ end
20
+
21
+ def sakuracloud_network_service
22
+ Fog::Network[:sakuracloud]
23
+ end
@@ -13,7 +13,7 @@ Shindo.tests('Fog::Compute[:sakuracloud] | list_plans request', ['sakuracloud',
13
13
  tests('success') do
14
14
 
15
15
  tests('#list_plans') do
16
- serverplans = compute_service.list_plans
16
+ serverplans = sakuracloud_compute_service.list_plans
17
17
  test 'returns a Hash' do
18
18
  serverplans.body.is_a? Hash
19
19
  end
@@ -13,7 +13,7 @@ Shindo.tests('Fog::Compute[:sakuracloud] | list_servers request', ['sakuracloud'
13
13
  tests('success') do
14
14
 
15
15
  tests('#list_servers') do
16
- servers = compute_service.list_servers
16
+ servers = sakuracloud_compute_service.list_servers
17
17
  test 'returns a Hash' do
18
18
  servers.body.is_a? Hash
19
19
  end
@@ -32,7 +32,7 @@ end
32
32
  Shindo.tests('Fog::Compute[:sakuracloud] | create_servers request', ['sakuracloud', 'compute']) do
33
33
  tests('success') do
34
34
  tests('#create_servers') do
35
- servers = compute_service.create_server('foobar', 2001)
35
+ servers = sakuracloud_compute_service.create_server(:name => 'foobar', :serverplan => 2001)
36
36
  test 'returns a Hash' do
37
37
  servers.body.is_a? Hash
38
38
  end
@@ -11,7 +11,7 @@ Shindo.tests('Fog::Compute[:sakuracloud] | list_ssh_keys request', ['sakuracloud
11
11
  tests('success') do
12
12
 
13
13
  tests('#list_ssh_keys') do
14
- sshkeys = compute_service.list_ssh_keys
14
+ sshkeys = sakuracloud_compute_service.list_ssh_keys
15
15
  test 'returns a Hash' do
16
16
  sshkeys.body.is_a? Hash
17
17
  end
@@ -11,7 +11,7 @@ Shindo.tests('Fog::Compute[:sakuracloud] | list_zones request', ['sakuracloud',
11
11
  tests('success') do
12
12
 
13
13
  tests('#list_zones') do
14
- zones = compute_service.list_zones
14
+ zones = sakuracloud_compute_service.list_zones
15
15
  test 'returns a Hash' do
16
16
  zones.body.is_a? Hash
17
17
  end
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+ Shindo.tests('Fog::Network[:sakuracloud] | list_routers request', ['sakuracloud', 'network']) do
3
+
4
+ @routers_create_format = {
5
+ 'Index' => Integer,
6
+ 'ID' => String,
7
+ 'Name' => String,
8
+ 'ServerCount' => Integer,
9
+ 'ApplianceCount' => Integer,
10
+ 'Subnets' => Array
11
+ }
12
+
13
+ @routers_list_format = {
14
+ 'Index' => Integer,
15
+ 'ID' => String,
16
+ 'Switch' => Hash
17
+ }
18
+
19
+ tests('success') do
20
+
21
+ tests('#list_routers') do
22
+ routers = sakuracloud_network_service.list_routers
23
+ test 'returns a Hash' do
24
+ routers.body.is_a? Hash
25
+ end
26
+ if Fog.mock?
27
+ tests('Routers').formats(@routers_list_format, false) do
28
+ routers.body['Internet'].first
29
+ end
30
+ else
31
+ returns(200) { routers.status }
32
+ returns(true) { routers.body.is_a? Hash }
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ Shindo.tests('Fog::Network[:sakuracloud] | create_router request', ['sakuracloud', 'network']) do
39
+ tests('success') do
40
+ tests('#create_router_with_internet_access') do
41
+ router = sakuracloud_network_service.create_router(:name => 'foobar', :networkmasklen => 28)
42
+ test 'returns a Hash' do
43
+ router.body.is_a? Hash
44
+ end
45
+
46
+ unless Fog.mock?
47
+ returns(202) { router.status }
48
+ returns(true) { router.body.is_a? Hash }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+ Shindo.tests('Fog::Network[:sakuracloud] | list_switches request', ['sakuracloud', 'network']) do
3
+
4
+ @switches_format = {
5
+ 'Index' => Integer,
6
+ 'ID' => String,
7
+ 'Name' => String,
8
+ 'ServerCount' => Integer,
9
+ 'ApplianceCount' => Integer,
10
+ 'Subnets' => Array
11
+ }
12
+
13
+ tests('success') do
14
+
15
+ tests('#list_switches') do
16
+ switches = sakuracloud_network_service.list_switches
17
+ test 'returns a Hash' do
18
+ switches.body.is_a? Hash
19
+ end
20
+ if Fog.mock?
21
+ tests('Switches').formats(@switches_format, false) do
22
+ switches.body['Switches'].first
23
+ end
24
+ else
25
+ returns(200) { switches.status }
26
+ returns(true) { switches.body.is_a? Hash }
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ Shindo.tests('Fog::Network[:sakuracloud] | create_switch request', ['sakuracloud', 'network']) do
33
+ tests('success') do
34
+ tests('#create_simple_switch') do
35
+ switch = sakuracloud_network_service.create_switch(:name => 'foobar')
36
+ test 'returns a Hash' do
37
+ switch.body.is_a? Hash
38
+ end
39
+
40
+ unless Fog.mock?
41
+ returns(201) { switch.status }
42
+ returns(true) { switch.body.is_a? Hash }
43
+ end
44
+ end
45
+ end
46
+ end
@@ -12,7 +12,7 @@ Shindo.tests('Fog::Volume[:sakuracloud] | list_archives request', ['sakuracloud'
12
12
  tests('success') do
13
13
 
14
14
  tests('#list_archives') do
15
- archives = volume_service.list_archives
15
+ archives = sakuracloud_volume_service.list_archives
16
16
  test 'returns a Hash' do
17
17
  archives.body.is_a? Hash
18
18
  end
@@ -14,7 +14,7 @@ Shindo.tests('Fog::Volume[:sakuracloud] | list_disks request', ['sakuracloud', '
14
14
  tests('success') do
15
15
 
16
16
  tests('#list_disks') do
17
- disks = volume_service.list_disks
17
+ disks = sakuracloud_volume_service.list_disks
18
18
  test 'returns a Hash' do
19
19
  disks.body.is_a? Hash
20
20
  end
@@ -33,7 +33,7 @@ end
33
33
  Shindo.tests('Fog::Volume[:sakuracloud] | create_disks request', ['sakuracloud', 'volume']) do
34
34
  tests('success') do
35
35
  tests('#create_disks') do
36
- disks = volume_service.create_disk('foobar', 4, 112500463685)
36
+ disks = sakuracloud_volume_service.create_disk('foobar', 4, 112500463685)
37
37
  test 'returns a Hash' do
38
38
  disks.body.is_a? Hash
39
39
  end
@@ -11,7 +11,7 @@ Shindo.tests('Fog::Volume[:sakuracloud] | list_plans request', ['sakuracloud', '
11
11
  tests('success') do
12
12
 
13
13
  tests('#list_plans') do
14
- diskplans = volume_service.list_plans
14
+ diskplans = sakuracloud_volume_service.list_plans
15
15
  test 'returns a Hash' do
16
16
  diskplans.body.is_a? Hash
17
17
  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: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawanoboly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-08 00:00:00.000000000 Z
11
+ date: 2014-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core
@@ -252,6 +252,7 @@ files:
252
252
  - .travis.yml
253
253
  - CHANGELOG.md
254
254
  - Gemfile
255
+ - Gemfile.edge
255
256
  - LICENSE.txt
256
257
  - README.md
257
258
  - Rakefile
@@ -268,12 +269,17 @@ files:
268
269
  - lib/fog/sakuracloud/models/compute/ssh_keys.rb
269
270
  - lib/fog/sakuracloud/models/compute/zone.rb
270
271
  - lib/fog/sakuracloud/models/compute/zones.rb
272
+ - lib/fog/sakuracloud/models/network/router.rb
273
+ - lib/fog/sakuracloud/models/network/routers.rb
274
+ - lib/fog/sakuracloud/models/network/switch.rb
275
+ - lib/fog/sakuracloud/models/network/switches.rb
271
276
  - lib/fog/sakuracloud/models/volume/archive.rb
272
277
  - lib/fog/sakuracloud/models/volume/archives.rb
273
278
  - lib/fog/sakuracloud/models/volume/disk.rb
274
279
  - lib/fog/sakuracloud/models/volume/disks.rb
275
280
  - lib/fog/sakuracloud/models/volume/plan.rb
276
281
  - lib/fog/sakuracloud/models/volume/plans.rb
282
+ - lib/fog/sakuracloud/network.rb
277
283
  - lib/fog/sakuracloud/requests/compute/boot_server.rb
278
284
  - lib/fog/sakuracloud/requests/compute/create_server.rb
279
285
  - lib/fog/sakuracloud/requests/compute/delete_server.rb
@@ -282,6 +288,12 @@ files:
282
288
  - lib/fog/sakuracloud/requests/compute/list_ssh_keys.rb
283
289
  - lib/fog/sakuracloud/requests/compute/list_zones.rb
284
290
  - lib/fog/sakuracloud/requests/compute/stop_server.rb
291
+ - lib/fog/sakuracloud/requests/network/create_router.rb
292
+ - lib/fog/sakuracloud/requests/network/create_switch.rb
293
+ - lib/fog/sakuracloud/requests/network/delete_router.rb
294
+ - lib/fog/sakuracloud/requests/network/delete_switch.rb
295
+ - lib/fog/sakuracloud/requests/network/list_routers.rb
296
+ - lib/fog/sakuracloud/requests/network/list_switches.rb
285
297
  - lib/fog/sakuracloud/requests/volume/attach_disk.rb
286
298
  - lib/fog/sakuracloud/requests/volume/configure_disk.rb
287
299
  - lib/fog/sakuracloud/requests/volume/create_disk.rb
@@ -292,11 +304,12 @@ files:
292
304
  - lib/fog/sakuracloud/version.rb
293
305
  - lib/fog/sakuracloud/volume.rb
294
306
  - tests/helper.rb
295
- - tests/sakuracloud/helper.rb
296
307
  - tests/sakuracloud/requests/compute/plans_tests.rb
297
308
  - tests/sakuracloud/requests/compute/servers_tests.rb
298
309
  - tests/sakuracloud/requests/compute/ssh_keys_tests.rb
299
310
  - tests/sakuracloud/requests/compute/zones_tests.rb
311
+ - tests/sakuracloud/requests/network/routers_tests.rb
312
+ - tests/sakuracloud/requests/network/switches_tests.rb
300
313
  - tests/sakuracloud/requests/volume/archives_tests.rb
301
314
  - tests/sakuracloud/requests/volume/disks_tests.rb
302
315
  - tests/sakuracloud/requests/volume/plans_tests.rb
@@ -1,7 +0,0 @@
1
- def volume_service
2
- Fog::Volume[:sakuracloud]
3
- end
4
-
5
- def compute_service
6
- Fog::Compute[:sakuracloud]
7
- end