fog-sakuracloud 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +65 -0
- data/.gitmodules +3 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +113 -0
- data/fog-sakuracloud.gemspec +41 -0
- data/gemfiles/Gemfile.1.8.7 +6 -0
- data/lib/fog/sakuracloud.rb +16 -0
- data/lib/fog/sakuracloud/compute.rb +65 -0
- data/lib/fog/sakuracloud/models/compute/plan.rb +15 -0
- data/lib/fog/sakuracloud/models/compute/plans.rb +22 -0
- data/lib/fog/sakuracloud/models/compute/server.rb +40 -0
- data/lib/fog/sakuracloud/models/compute/servers.rb +63 -0
- data/lib/fog/sakuracloud/models/compute/ssh_key.rb +13 -0
- data/lib/fog/sakuracloud/models/compute/ssh_keys.rb +22 -0
- data/lib/fog/sakuracloud/models/compute/zone.rb +13 -0
- data/lib/fog/sakuracloud/models/compute/zones.rb +22 -0
- data/lib/fog/sakuracloud/models/volume/archive.rb +14 -0
- data/lib/fog/sakuracloud/models/volume/archives.rb +22 -0
- data/lib/fog/sakuracloud/models/volume/disk.rb +37 -0
- data/lib/fog/sakuracloud/models/volume/disks.rb +27 -0
- data/lib/fog/sakuracloud/models/volume/plan.rb +12 -0
- data/lib/fog/sakuracloud/models/volume/plans.rb +22 -0
- data/lib/fog/sakuracloud/requests/compute/boot_server.rb +31 -0
- data/lib/fog/sakuracloud/requests/compute/create_server.rb +41 -0
- data/lib/fog/sakuracloud/requests/compute/delete_server.rb +33 -0
- data/lib/fog/sakuracloud/requests/compute/list_plans.rb +46 -0
- data/lib/fog/sakuracloud/requests/compute/list_servers.rb +44 -0
- data/lib/fog/sakuracloud/requests/compute/list_ssh_keys.rb +40 -0
- data/lib/fog/sakuracloud/requests/compute/list_zones.rb +40 -0
- data/lib/fog/sakuracloud/requests/compute/stop_server.rb +37 -0
- data/lib/fog/sakuracloud/requests/volume/attach_disk.rb +30 -0
- data/lib/fog/sakuracloud/requests/volume/configure_disk.rb +35 -0
- data/lib/fog/sakuracloud/requests/volume/create_disk.rb +43 -0
- data/lib/fog/sakuracloud/requests/volume/delete_disk.rb +30 -0
- data/lib/fog/sakuracloud/requests/volume/list_archives.rb +46 -0
- data/lib/fog/sakuracloud/requests/volume/list_disks.rb +50 -0
- data/lib/fog/sakuracloud/requests/volume/list_plans.rb +40 -0
- data/lib/fog/sakuracloud/version.rb +5 -0
- data/lib/fog/sakuracloud/volume.rb +88 -0
- data/tests/helper.rb +8 -0
- data/tests/sakuracloud/helper.rb +7 -0
- data/tests/sakuracloud/requests/compute/plans_tests.rb +32 -0
- data/tests/sakuracloud/requests/compute/servers_tests.rb +46 -0
- data/tests/sakuracloud/requests/compute/ssh_keys_tests.rb +30 -0
- data/tests/sakuracloud/requests/compute/zones_tests.rb +30 -0
- data/tests/sakuracloud/requests/volume/archives_tests.rb +31 -0
- data/tests/sakuracloud/requests/volume/disks_tests.rb +47 -0
- data/tests/sakuracloud/requests/volume/plans_tests.rb +30 -0
- metadata +326 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Compute
|
5
|
+
class SakuraCloud
|
6
|
+
class Server < Fog::Model
|
7
|
+
identity :id, :aliases => 'ID'
|
8
|
+
attribute :name, :aliases => 'Name'
|
9
|
+
attribute :server_plan, :aliases => 'ServerPlan'
|
10
|
+
attribute :instance, :aliases => 'Instance'
|
11
|
+
attribute :disks, :aliases => 'Disks'
|
12
|
+
attribute :interfaces, :aliases => 'Interfaces'
|
13
|
+
|
14
|
+
def save
|
15
|
+
requires :name, :server_plan
|
16
|
+
data = service.create_server(@attributes[:name], @attributes[:server_plan]).body["Server"]
|
17
|
+
merge_attributes(data)
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def boot
|
22
|
+
requires :id
|
23
|
+
service.boot_server(@attributes[:id])
|
24
|
+
end
|
25
|
+
|
26
|
+
def stop(force = false)
|
27
|
+
requires :id
|
28
|
+
service.stop_server(@attributes[:id], force)
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete(disks = [])
|
32
|
+
requires :id
|
33
|
+
service.delete_server(@attributes[:id], disks)
|
34
|
+
true
|
35
|
+
end
|
36
|
+
alias_method :destroy, :delete
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/sakuracloud/models/compute/server'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Compute
|
6
|
+
class SakuraCloud
|
7
|
+
class Servers < Fog::Collection
|
8
|
+
model Fog::Compute::SakuraCloud::Server
|
9
|
+
|
10
|
+
def all
|
11
|
+
load service.list_servers.body['Servers']
|
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 create(options = {})
|
21
|
+
user = options[:user] || 'root'
|
22
|
+
Fog::Logger.warning("Create Server")
|
23
|
+
data = service.create_server(Fog::UUID.uuid, options[:serverplan]).body["Server"]
|
24
|
+
server = service.servers.new
|
25
|
+
server.merge_attributes(data)
|
26
|
+
|
27
|
+
if options[:volume]
|
28
|
+
disk = create_and_attach_volume(server, options)
|
29
|
+
server.reload
|
30
|
+
end
|
31
|
+
server.boot if options[:boot]
|
32
|
+
server
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def create_and_attach_volume(server, options)
|
37
|
+
Fog::Logger.warning("Create Volume")
|
38
|
+
sakuracloud_api_token = options[:sakuracloud_api_token] || Fog.credentials[:sakuracloud_api_token]
|
39
|
+
sakuracloud_api_token_secret = options[:sakuracloud_api_token_secret] || Fog.credentials[:sakuracloud_api_token_secret]
|
40
|
+
volume = Fog::Volume::SakuraCloud.new(:sakuracloud_api_token => sakuracloud_api_token, :sakuracloud_api_token_secret => sakuracloud_api_token_secret)
|
41
|
+
disk = volume.disks.create :name => Fog::UUID.uuid,
|
42
|
+
:plan => options[:volume][:diskplan].to_i,
|
43
|
+
:source_archive => options[:volume][:sourcearchive].to_s
|
44
|
+
Fog::Logger.warning("Waiting disk until available")
|
45
|
+
disk.wait_for { availability == 'available' }
|
46
|
+
volume.attach_disk(disk.id, server.id)
|
47
|
+
disk_attached?(server, disk.id)
|
48
|
+
Fog::Logger.warning("Modifing disk")
|
49
|
+
volume.configure_disk(disk.id, options[:sshkey])
|
50
|
+
disk
|
51
|
+
end
|
52
|
+
|
53
|
+
def disk_attached?(server, disk_id)
|
54
|
+
until server.disks.find {|s| disk_id.to_s}
|
55
|
+
print '.'
|
56
|
+
sleep 2
|
57
|
+
server.reload
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/sakuracloud/models/compute/ssh_key'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Compute
|
6
|
+
class SakuraCloud
|
7
|
+
class SshKeys < Fog::Collection
|
8
|
+
model Fog::Compute::SakuraCloud::SshKey
|
9
|
+
|
10
|
+
def all
|
11
|
+
load service.list_ssh_keys.body['SSHKeys']
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(id)
|
15
|
+
all.find { |f| f.id == id }
|
16
|
+
rescue Fog::Errors::NotFound
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/sakuracloud/models/compute/zone'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Compute
|
6
|
+
class SakuraCloud
|
7
|
+
class Zones < Fog::Collection
|
8
|
+
model Fog::Compute::SakuraCloud::Zone
|
9
|
+
|
10
|
+
def all
|
11
|
+
load service.list_zones.body['Zones']
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(id)
|
15
|
+
all.find { |f| f.id == id }
|
16
|
+
rescue Fog::Errors::NotFound
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Volume
|
5
|
+
class SakuraCloud
|
6
|
+
class Archive < Fog::Model
|
7
|
+
identity :id, :aliases => 'ID'
|
8
|
+
attribute :name, :aliases => 'Name'
|
9
|
+
attribute :size_mb, :aliases => 'SizeMB'
|
10
|
+
attribute :plan, :aliases => 'Plan'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/sakuracloud/models/volume/archive'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Volume
|
6
|
+
class SakuraCloud
|
7
|
+
class Archives < Fog::Collection
|
8
|
+
model Fog::Volume::SakuraCloud::Archive
|
9
|
+
|
10
|
+
def all
|
11
|
+
load service.list_archives.body['Archives']
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(id)
|
15
|
+
all.find { |f| f.id == id }
|
16
|
+
rescue Fog::Errors::NotFound
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Volume
|
5
|
+
class SakuraCloud
|
6
|
+
class Disk < Fog::Model
|
7
|
+
identity :id, :aliases => 'ID'
|
8
|
+
attribute :name, :aliases => 'Name'
|
9
|
+
attribute :connection, :aliases => 'Connection'
|
10
|
+
attribute :availability, :aliases => 'Availability'
|
11
|
+
attribute :plan, :aliases => 'Plan'
|
12
|
+
attribute :size_mb, :aliases => 'SizeMB'
|
13
|
+
attribute :source_disk, :aliases => 'SourceDisk'
|
14
|
+
attribute :source_archive, :aliases => 'SourceArchive'
|
15
|
+
|
16
|
+
def delete
|
17
|
+
service.delete_disk(identity)
|
18
|
+
true
|
19
|
+
end
|
20
|
+
alias_method :destroy, :delete
|
21
|
+
|
22
|
+
def save
|
23
|
+
requires :name, :plan, :source_archive
|
24
|
+
data = service.create_disk(@attributes[:name], @attributes[:plan], @attributes[:source_archive]).body["Disk"]
|
25
|
+
merge_attributes(data)
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def configure(sshkey_id)
|
30
|
+
requires :id
|
31
|
+
service.configure_disk(@attributes[:id], sshkey_id )
|
32
|
+
true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/sakuracloud/models/volume/disk'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Volume
|
6
|
+
class SakuraCloud
|
7
|
+
class Disks < Fog::Collection
|
8
|
+
model Fog::Volume::SakuraCloud::Disk
|
9
|
+
|
10
|
+
def all
|
11
|
+
load service.list_disks.body['Disks']
|
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_disk(id)
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/sakuracloud/models/volume/plan'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Volume
|
6
|
+
class SakuraCloud
|
7
|
+
class Plans < Fog::Collection
|
8
|
+
model Fog::Volume::SakuraCloud::Plan
|
9
|
+
|
10
|
+
def all
|
11
|
+
load service.list_plans.body['DiskPlans']
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(id)
|
15
|
+
all.find { |f| f.id == id }
|
16
|
+
rescue Fog::Errors::NotFound
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Compute
|
5
|
+
class SakuraCloud
|
6
|
+
class Real
|
7
|
+
def boot_server( id )
|
8
|
+
request(
|
9
|
+
:headers => {
|
10
|
+
'Authorization' => "Basic #{@auth_encord}"
|
11
|
+
},
|
12
|
+
:expects => [200],
|
13
|
+
:method => 'PUT',
|
14
|
+
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/server/#{id}/power"
|
15
|
+
)
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end # Real
|
19
|
+
|
20
|
+
class Mock
|
21
|
+
def boot_server( id )
|
22
|
+
response = Excon::Response.new
|
23
|
+
response.status = 200
|
24
|
+
response.body = {
|
25
|
+
}
|
26
|
+
response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end # SakuraCloud
|
30
|
+
end # Volume
|
31
|
+
end # Fog
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Compute
|
5
|
+
class SakuraCloud
|
6
|
+
class Real
|
7
|
+
def create_server( name, serverplan )
|
8
|
+
body = {
|
9
|
+
"Server" => {
|
10
|
+
"Name" => name,
|
11
|
+
"ServerPlan" => {
|
12
|
+
"ID" => serverplan.to_i
|
13
|
+
},
|
14
|
+
"ConnectedSwitches"=>[{"Scope"=>"shared", "BandWidthMbps"=>100}]
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
request(
|
19
|
+
:headers => {
|
20
|
+
'Authorization' => "Basic #{@auth_encord}"
|
21
|
+
},
|
22
|
+
:expects => [201],
|
23
|
+
:method => 'POST',
|
24
|
+
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/server",
|
25
|
+
:body => Fog::JSON.encode(body)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end # Real
|
29
|
+
|
30
|
+
class Mock
|
31
|
+
def create_server( name, serverplan )
|
32
|
+
response = Excon::Response.new
|
33
|
+
response.status = 201
|
34
|
+
response.body = {
|
35
|
+
}
|
36
|
+
response
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end # SakuraCloud
|
40
|
+
end # Volume
|
41
|
+
end # Fog
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Compute
|
5
|
+
class SakuraCloud
|
6
|
+
class Real
|
7
|
+
def delete_server( id, force = false, disks = [] )
|
8
|
+
body = { "Force" => force, 'WithDisk' => disks }
|
9
|
+
|
10
|
+
request(
|
11
|
+
:headers => {
|
12
|
+
'Authorization' => "Basic #{@auth_encord}"
|
13
|
+
},
|
14
|
+
:expects => [200],
|
15
|
+
:method => 'DELETE',
|
16
|
+
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/server/#{id}",
|
17
|
+
:body => Fog::JSON.encode(body)
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end # Real
|
21
|
+
|
22
|
+
class Mock
|
23
|
+
def delete_server( id, force = false, disks = [] )
|
24
|
+
response = Excon::Response.new
|
25
|
+
response.status = 200
|
26
|
+
response.body = {
|
27
|
+
}
|
28
|
+
response
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end # SakuraCloud
|
32
|
+
end # Volume
|
33
|
+
end # Fog
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Compute
|
5
|
+
class SakuraCloud
|
6
|
+
class Real
|
7
|
+
def list_plans(options = {})
|
8
|
+
request(
|
9
|
+
:headers => {
|
10
|
+
'Authorization' => "Basic #{@auth_encord}"
|
11
|
+
},
|
12
|
+
:method => 'GET',
|
13
|
+
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/product/server"
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Mock
|
19
|
+
def list_plans(options = {})
|
20
|
+
response = Excon::Response.new
|
21
|
+
response.status = 200
|
22
|
+
response.body = {
|
23
|
+
"ServerPlans" =>
|
24
|
+
[
|
25
|
+
{"Index"=>0,
|
26
|
+
"ID"=>1001,
|
27
|
+
"Name"=>"プラン/1Core-1GB",
|
28
|
+
"CPU"=>1,
|
29
|
+
"MemoryMB"=>1024,
|
30
|
+
"ServiceClass"=>"cloud/plan/1core-1gb",
|
31
|
+
"Availability"=>"available"},
|
32
|
+
{"Index"=>1,
|
33
|
+
"ID"=>2001,
|
34
|
+
"Name"=>"プラン/1Core-2GB",
|
35
|
+
"CPU"=>1,
|
36
|
+
"MemoryMB"=>2048,
|
37
|
+
"ServiceClass"=>"cloud/plan/1core-2gb",
|
38
|
+
"Availability"=>"available"}
|
39
|
+
]
|
40
|
+
}
|
41
|
+
response
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|