mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
remove sakuracloud libs and add fog sakura-cloud to gem depends
This commit is contained in:
parent
4e6929c772
commit
491a186d57
42 changed files with 1 additions and 1802 deletions
|
@ -50,6 +50,7 @@ Gem::Specification.new do |s|
|
|||
# Modular providers
|
||||
s.add_dependency("fog-brightbox")
|
||||
s.add_dependency("fog-softlayer")
|
||||
s.add_dependency("fog-sakuracloud")
|
||||
|
||||
## List your development dependencies here. Development dependencies are
|
||||
## those that are only needed during development
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
require 'fog/core'
|
||||
require 'fog/sakuracloud/compute'
|
||||
require 'fog/sakuracloud/volume'
|
||||
|
||||
module Fog
|
||||
module SakuraCloud
|
||||
extend Fog::Provider
|
||||
|
||||
SAKURACLOUD_API_VERSION = '1.1' unless defined? SAKURACLOUD_API_VERSION
|
||||
SAKURACLOUD_API_ZONE = "is1b" unless defined? SAKURACLOUD_API_ZONE
|
||||
SAKURACLOUD_API_ENDPOINT = "/cloud/zone/#{SAKURACLOUD_API_ZONE}/api/cloud/#{SAKURACLOUD_API_VERSION}/"
|
||||
|
||||
service(:compute, 'Compute')
|
||||
service(:volume, 'Volume')
|
||||
end
|
||||
end
|
|
@ -1,65 +0,0 @@
|
|||
require 'fog/sakuracloud'
|
||||
require 'fog/compute'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud < Fog::Service
|
||||
requires :sakuracloud_api_token
|
||||
requires :sakuracloud_api_token_secret
|
||||
|
||||
recognizes :sakuracloud_api_url
|
||||
|
||||
model_path 'fog/sakuracloud/models/compute'
|
||||
model :server
|
||||
collection :servers
|
||||
model :plan
|
||||
collection :plans
|
||||
model :ssh_key
|
||||
collection :ssh_keys
|
||||
model :zone
|
||||
collection :zones
|
||||
|
||||
request_path 'fog/sakuracloud/requests/compute'
|
||||
request :list_servers
|
||||
request :create_server
|
||||
request :delete_server
|
||||
request :boot_server
|
||||
request :stop_server
|
||||
request :list_plans
|
||||
request :list_ssh_keys
|
||||
request :list_zones
|
||||
|
||||
class Real
|
||||
def initialize(options = {})
|
||||
@auth_encord = Base64.strict_encode64([
|
||||
options[:sakuracloud_api_token],
|
||||
options[:sakuracloud_api_token_secret]
|
||||
].join(':'))
|
||||
Fog.credentials[:sakuracloud_api_token] = options[:sakuracloud_api_token]
|
||||
Fog.credentials[:sakuracloud_api_token_secret] = options[:sakuracloud_api_token_secret]
|
||||
|
||||
@sakuracloud_api_url = options[:sakuracloud_api_url] || 'https://secure.sakura.ad.jp'
|
||||
|
||||
@connection = Fog::Core::Connection.new(@sakuracloud_api_url)
|
||||
end
|
||||
|
||||
def request(params)
|
||||
response = parse @connection.request(params)
|
||||
response
|
||||
end
|
||||
|
||||
private
|
||||
def parse(response)
|
||||
return response if response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def initialize(options = {})
|
||||
end
|
||||
end
|
||||
end #SakuraCloud
|
||||
end #Compute
|
||||
end
|
|
@ -1,450 +0,0 @@
|
|||
# Getting started for SakuraCloud
|
||||
|
||||
## Links
|
||||
|
||||
- Product Information: http://cloud.sakura.ad.jp/
|
||||
- API Reference(1.1): http://developer.sakura.ad.jp/cloud/api/1.1/
|
||||
|
||||
## Requeirement
|
||||
|
||||
- API TOKEN
|
||||
- API TOKEN SECRET
|
||||
|
||||
You can retreave them from dashboard.
|
||||
|
||||
|
||||
## Resources
|
||||
|
||||
|Service |Class |Description |
|
||||
|----|----|----|
|
||||
|Volume(disk) |Fog::Volume::SakuraCloud |Block device for server. |
|
||||
|Compute |Fog::Compute::SakuraCloud |Server. |
|
||||
|
||||
## Simple start
|
||||
|
||||
Inital boot from template with ssh key.
|
||||
|
||||
```
|
||||
require 'fog'
|
||||
compute = Fog::Compute::SakuraCloud.new(
|
||||
:sakuracloud_api_token => 'YOUR_API_TOKEN',
|
||||
:sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET'
|
||||
)
|
||||
|
||||
|
||||
server = compute.servers.create({
|
||||
:sakuracloud_api_token => 'YOUR_API_TOKEN',
|
||||
:sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET',
|
||||
:sshkey => '11260003****', # Your SSH Key id
|
||||
:serverplan => '2001', # Server Type
|
||||
:volume => {
|
||||
:diskplan => 4, # Type SSD
|
||||
:sourcearchive => '112500463685' # Ubuntu12.04
|
||||
},
|
||||
:boot => true
|
||||
})
|
||||
```
|
||||
|
||||
You can login or integrate with configuration management tools to server at once.
|
||||
|
||||
|
||||
## Services
|
||||
|
||||
Usage for SakuraCloud Services.
|
||||
|
||||
### Volume(disk) Service
|
||||
|
||||
Initailize Volume service.
|
||||
|
||||
```
|
||||
require 'fog'
|
||||
volume = Fog::Volume::SakuraCloud.new(
|
||||
:sakuracloud_api_token => 'YOUR_API_TOKEN',
|
||||
:sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET'
|
||||
)
|
||||
```
|
||||
|
||||
or initailize with `Fog.credentials`
|
||||
|
||||
|
||||
```
|
||||
Fog.credentials[:sakuracloud_api_token] = 'YOUR_API_TOKEN'
|
||||
Fog.credentials[:sakuracloud_api_token_secret] = 'YOUR_API_TOKEN_SECRET'
|
||||
|
||||
volume = Fog::Volume[:sakuracloud]
|
||||
```
|
||||
|
||||
|
||||
#### Listing disk plans
|
||||
|
||||
use `volume.plans`.
|
||||
|
||||
```
|
||||
> volume.plans
|
||||
|
||||
=> [ <Fog::Volume::SakuraCloud::Plan
|
||||
id=4,
|
||||
name="SSDプラン"
|
||||
>,
|
||||
<Fog::Volume::SakuraCloud::Plan
|
||||
id=2,
|
||||
name="標準プラン"
|
||||
>]
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Listing volume templates(archives)
|
||||
|
||||
use `volume.archives`.
|
||||
|
||||
```
|
||||
require 'fog'
|
||||
volume = Fog::Volume::SakuraCloud.new(
|
||||
:sakuracloud_api_token => 'YOUR_API_TOKEN',
|
||||
:sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET'
|
||||
)
|
||||
|
||||
|
||||
> volume.archives
|
||||
|
||||
=> [ <Fog::Volume::SakuraCloud::Archive
|
||||
id="112500514887",
|
||||
name="CentOS 5.10 64bit (基本セット)"
|
||||
>,
|
||||
<Fog::Volume::SakuraCloud::Archive
|
||||
id="112500571575",
|
||||
name="CentOS 6.5 64bit (基本セット)"
|
||||
>,
|
||||
<Fog::Volume::SakuraCloud::Archive
|
||||
id="112500556904",
|
||||
name="Scientific Linux 6.4 64bit (基本セット)"
|
||||
>,
|
||||
<Fog::Volume::SakuraCloud::Archive
|
||||
id="112500587018",
|
||||
name="Scientific Linux 6.5 RC1 64bit (基本セット)"
|
||||
>,
|
||||
<Fog::Volume::SakuraCloud::Archive
|
||||
id="112500556903",
|
||||
name="FreeBSD 8.3 64bit (基本セット)"
|
||||
>,
|
||||
<Fog::Volume::SakuraCloud::Archive
|
||||
id="112500556906",
|
||||
name="FreeBSD 9.1 64bit (基本セット)"
|
||||
>,
|
||||
<Fog::Volume::SakuraCloud::Archive
|
||||
id="112500556907",
|
||||
name="Ubuntu Server 13.04 64bit (基本セット)"
|
||||
>,
|
||||
<Fog::Volume::SakuraCloud::Archive
|
||||
id="112500463685",
|
||||
name="Ubuntu Server 12.04.3 LTS 64bit (基本セット)"
|
||||
>,
|
||||
<Fog::Volume::SakuraCloud::Archive
|
||||
id="112500490219",
|
||||
name="Ubuntu Server 13.10 64bit(基本セット)"
|
||||
>,
|
||||
<Fog::Volume::SakuraCloud::Archive
|
||||
id="112500556909",
|
||||
name="Debian GNU/Linux 6.0.7 64bit (基本セット)"
|
||||
>,
|
||||
-- snip --
|
||||
```
|
||||
|
||||
#### Create volume from templates(archives)
|
||||
|
||||
use `volume.disks.create` with `:name`, `:plan`(Plan id) and `:source_archive`(id, optional)
|
||||
|
||||
##### Example: Create SSD installed 'Ubuntu 12.04'.
|
||||
|
||||
```
|
||||
disk = volume.disks.create :name => 'foobar',
|
||||
:plan => 4, # Type SSD
|
||||
:source_archive => 112500463685 # Ubuntu12.04
|
||||
```
|
||||
|
||||
It creates disk.
|
||||
|
||||
```
|
||||
=> <Fog::Volume::SakuraCloud::Disk
|
||||
id="112600053876",
|
||||
name="foobar",
|
||||
Connection="virtio",
|
||||
Availability="migrating",
|
||||
Plan={"id"=>4, "StorageClass"=>"iscsi1204", "name"=>"SSDプラン"},
|
||||
SizeMB=20480,
|
||||
SourceDisk=nil,
|
||||
SourceArchive={"id"=>"112500463685", "name"=>"Ubuntu Server 12.04.3 LTS 64bit (基本セット)", "Availability"=>"available", "SizeMB"=>20480, "Plan"=>{"id"=>2, "StorageClass"=>"iscsi1204", "name"=>"標準プラン"}, "Storage"=>{"id"=>"3100297001", "Class"=>"iscsi1204", "name"=>"sac-is1b-arc-st01", "Zone"=>{"id"=>31002, "name"=>"is1b", "Region"=>{"id"=>310, "name"=>"石狩"}}, "DiskPlan"=>{"id"=>2, "StorageClass"=>"iscsi1204", "name"=>"標準プラン"}}, "BundleInfo"=>nil}
|
||||
>
|
||||
```
|
||||
|
||||
#### Listing available disks
|
||||
|
||||
use `volume.disks`
|
||||
|
||||
```
|
||||
> volume.disks
|
||||
|
||||
=> [ <Fog::Volume::SakuraCloud::Disk
|
||||
id="112600053837",
|
||||
name="ed86efca-d7f1-4367-97df-30e16c4f331e",
|
||||
Connection="virtio",
|
||||
Availability="available",
|
||||
Plan={"id"=>4, "StorageClass"=>"iscsi1204", "name"=>"SSDプラン"},
|
||||
SizeMB=20480,
|
||||
SourceDisk=nil,
|
||||
SourceArchive={"id"=>"112500463685", "name"=>"Ubuntu Server 12.04.3 LTS 64bit (基本セット)", "Availability"=>"available", "SizeMB"=>20480, "Plan"=>{"id"=>2, "StorageClass"=>"iscsi1204", "Na
|
||||
>,
|
||||
<Fog::Volume::SakuraCloud::Disk
|
||||
id="112600053840",
|
||||
name="2a3f571a-2562-49e1-a4ea-86f7cf34c571",
|
||||
Connection="virtio",
|
||||
Availability="available",
|
||||
Plan={"id"=>4, "StorageClass"=>"iscsi1204", "name"=>"SSDプラン"},
|
||||
SizeMB=20480,
|
||||
SourceDisk=nil,
|
||||
SourceArchive={"id"=>"112500463685", "name"=>"Ubuntu Server 12.04.3 LTS 64bit (基本セット)", "Availability"=>"available", "SizeMB"=>20480, "Plan"=>{"id"=>2, "StorageClass"=>"iscsi1204", "Na
|
||||
>,
|
||||
-- snip --
|
||||
|
||||
```
|
||||
|
||||
Get Disk id or any attributes.
|
||||
|
||||
```
|
||||
> volume.disks.first.id
|
||||
=> "112600053837"
|
||||
|
||||
> volume.disks.first.SizeMB
|
||||
=> 20480
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```
|
||||
> disk = volume.disks.first
|
||||
> disk.id
|
||||
=> "112600053837"
|
||||
```
|
||||
|
||||
You can reload disk attributes.
|
||||
|
||||
```
|
||||
> disk.reload
|
||||
=> <Fog::Volume::SakuraCloud::Disk
|
||||
id="112600053837",
|
||||
name="ed86efca-d7f1-4367-97df-30e16c4f331e",
|
||||
Connection="virtio",
|
||||
Availability="available",
|
||||
Plan={"id"=>4, "StorageClass"=>"iscsi1204", "name"=>"SSDプラン"},
|
||||
SizeMB=20480,
|
||||
SourceDisk=nil,
|
||||
SourceArchive={"id"=>"112500463685", "name"=>"Ubuntu Server 12.04.3 LTS 64bit (基本セット)", "Availability"=>"available", "SizeMB"=>20480, "Plan"=>{"id"=>2, "StorageClass"=>"iscsi1204", "name"=>"標準プラン"}, "Storage"=>{"id"=>"3100297001", "Class"=>"iscsi1204", "name"=>"sac-is1b-arc-st01", "Zone"=>{"id"=>31002, "name"=>"is1b", "Region"=>{"id"=>310, "name"=>"石狩"}}, "DiskPlan"=>{"id"=>2, "StorageClass"=>"iscsi1204", "name"=>"標準プラン"}}, "BundleInfo"=>nil}
|
||||
>
|
||||
```
|
||||
|
||||
#### Delete disk
|
||||
|
||||
use `volume.disks.delete('Disk_id')`
|
||||
|
||||
```
|
||||
> volume.disks.delete('112600053837')
|
||||
|
||||
=> true
|
||||
```
|
||||
|
||||
or execute delete method for disk.
|
||||
|
||||
```
|
||||
> volume.disks.first.delete
|
||||
|
||||
=> true
|
||||
```
|
||||
|
||||
##### Example: Delete all disks
|
||||
|
||||
```
|
||||
> volume.disks.each {|d| d.delete}
|
||||
```
|
||||
|
||||
|
||||
### SSH Key Service (Part of the Compute Service)
|
||||
|
||||
Initailize Compute service.
|
||||
|
||||
```
|
||||
require 'fog'
|
||||
compute = Fog::Compute::SakuraCloud.new(
|
||||
:sakuracloud_api_token => 'YOUR_API_TOKEN',
|
||||
:sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET'
|
||||
)
|
||||
```
|
||||
|
||||
#### Listing SSH Keys
|
||||
|
||||
use `compute.ssh_keys`
|
||||
|
||||
```
|
||||
> compute.ssh_keys
|
||||
|
||||
=> [ <Fog::Compute::SakuraCloud::SshKey
|
||||
id="11260003****",
|
||||
name="sawanobori",
|
||||
PublicKey="ssh-rsa ***********************"
|
||||
>]
|
||||
```
|
||||
|
||||
|
||||
#### Add SSH Key to disk.
|
||||
|
||||
Work with Volume service.
|
||||
|
||||
use `configure` method with SSH Key id.
|
||||
|
||||
##### Example
|
||||
|
||||
```
|
||||
> volume.disks.first.configure(11260003****)
|
||||
|
||||
=> true
|
||||
```
|
||||
|
||||
|
||||
### Compute Service
|
||||
|
||||
Initailize Compute service.
|
||||
|
||||
```
|
||||
require 'fog'
|
||||
compute = Fog::Compute::SakuraCloud.new(
|
||||
:sakuracloud_api_token => 'YOUR_API_TOKEN',
|
||||
:sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET'
|
||||
)
|
||||
```
|
||||
|
||||
or initailize with `Fog.credentials`
|
||||
|
||||
|
||||
```
|
||||
Fog.credentials[:sakuracloud_api_token] = 'YOUR_API_TOKEN'
|
||||
Fog.credentials[:sakuracloud_api_token_secret] = 'YOUR_API_TOKEN_SECRET'
|
||||
|
||||
volume = Fog::Compute[:sakuracloud]
|
||||
```
|
||||
|
||||
|
||||
#### Listing server plans
|
||||
|
||||
use `compute.plans`.
|
||||
|
||||
```
|
||||
> compute.plans
|
||||
|
||||
=> [ <Fog::Compute::SakuraCloud::Plan
|
||||
id=1001,
|
||||
name="プラン/1Core-1GB",
|
||||
ServiceClass="cloud/plan/1core-1gb",
|
||||
CPU=1,
|
||||
MemoryMB=1024
|
||||
>,
|
||||
<Fog::Compute::SakuraCloud::Plan
|
||||
id=2001,
|
||||
name="プラン/1Core-2GB",
|
||||
ServiceClass="cloud/plan/1core-2gb",
|
||||
CPU=1,
|
||||
MemoryMB=2048
|
||||
>,
|
||||
-- snip --
|
||||
```
|
||||
|
||||
|
||||
#### Listing zones
|
||||
|
||||
use `compute.zones`.
|
||||
|
||||
```
|
||||
> compute.zones
|
||||
|
||||
=> [ <Fog::Compute::SakuraCloud::Zone
|
||||
id=31001,
|
||||
name="is1a",
|
||||
Description="石狩第1ゾーン"
|
||||
>,
|
||||
<Fog::Compute::SakuraCloud::Zone
|
||||
id=31002,
|
||||
name="is1b",
|
||||
Description="石狩第2ゾーン"
|
||||
>]
|
||||
```
|
||||
|
||||
#### Create server
|
||||
|
||||
use `volume.servers.create` with `:name`, `:ServerPlan`(Plan id)
|
||||
|
||||
##### Example: Create server with public switch connection.
|
||||
|
||||
```
|
||||
server = compute.servers.create :name => 'foobar',
|
||||
:ServerPlan => 2001
|
||||
```
|
||||
|
||||
It creates server.
|
||||
|
||||
```
|
||||
=> <Fog::Compute::SakuraCloud::Server
|
||||
id="112600055437",
|
||||
name="foobar",
|
||||
ServerPlan={"id"=>2001, "name"=>"プラン/1Core-2GB", "CPU"=>1, "MemoryMB"=>2048, "ServiceClass"=>"cloud/plan/1core-2gb", "Availability"=>"available"},
|
||||
Instance={"Server"=>{"id"=>"112600055437"}, "Status"=>"down", "BeforeStatus"=>nil, "StatusChangedAt"=>nil, "MigrationProgress"=>nil, "MigrationSchedule"=>nil, "IsMigrating"=>nil, "MigrationAllowed"=>nil, "ModifiedAt"=>"2014-01-30T23:54:47+09:00", "Host"=>nil, "CDROM"=>nil, "CDROMStorage"=>nil},
|
||||
Disks=[],
|
||||
Interfaces=[{"id"=>"112600055438", "MACAddress"=>"9C:A3:BA:30:13:28", "IPAddress"=>"133.242.236.247", "UserIPAddress"=>nil, "Hostname"=>nil, "Switch"=>{"id"=>"112500556860", "name"=>"スイッチ", "Scope"=>"shared", "Subnet"=>{"id"=>nil, "NetworkAddress"=>"133.242.236.0", "NetworkMaskLen"=>24, "DefaultRoute"=>"133.242.236.1", "Internet"=>{"BandWidthMbps"=>100}}, "UserSubnet"=>nil}, "PacketFilter"=>nil}]
|
||||
>
|
||||
```
|
||||
|
||||
#### Listing available servers
|
||||
|
||||
use `compute.servers`
|
||||
|
||||
```
|
||||
> compute.servers
|
||||
|
||||
=> [ <Fog::Compute::SakuraCloud::Server
|
||||
id="112600055437",
|
||||
name="foobar",
|
||||
ServerPlan={"id"=>2001, "name"=>"プラン/1Core-2GB", "CPU"=>1, "MemoryMB"=>2048, "ServiceClass"=>"cloud/plan/1core-2gb", "Availability"=>"available"},
|
||||
Instance={"Server"=>{"id"=>"112600055437"}, "Status"=>"down", "BeforeStatus"=>nil, "StatusChangedAt"=>nil, "MigrationProgress"=>nil, "MigrationSchedule"=>nil, "IsMigrating"=>nil, "MigrationAllowed"=>nil, "ModifiedAt"=>"2014-01-30T23:54:47+09:00", "Host"=>nil, "CDROM"=>nil, "CDROMStorage"=>nil},
|
||||
Disks=[],
|
||||
Interfaces=[{"id"=>"112600055438", "MACAddress"=>"9C:A3:BA:30:13:28", "IPAddress"=>"133.242.236.247", "UserIPAddress"=>nil, "Hostname"=>nil, "Switch"=>{"id"=>"112500556860", "name"=>"スイッチ", "Scope"=>"shared", "Subnet"=>{"id"=>nil, "NetworkAddress"=>"133.242.236.0", "NetworkMaskLen"=>24, "DefaultRoute"=>"133.242.236.1", "Internet"=>{"BandWidthMbps"=>100}}, "UserSubnet"=>nil}, "PacketFilter"=>nil}]
|
||||
>]
|
||||
|
||||
```
|
||||
|
||||
|
||||
#### Boot or stop servers
|
||||
|
||||
execute boot/stop method for server.
|
||||
|
||||
|
||||
##### Example: boot server
|
||||
|
||||
```
|
||||
> compute.servers.first.boot
|
||||
|
||||
=> true
|
||||
```
|
||||
|
||||
##### Example: stop server
|
||||
|
||||
```
|
||||
> compute.servers.first.stop
|
||||
|
||||
=> true
|
||||
```
|
||||
|
||||
force stop
|
||||
|
||||
```
|
||||
> compute.servers.first.stop(true)
|
||||
|
||||
=> true
|
||||
```
|
|
@ -1,15 +0,0 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Plan < Fog::Model
|
||||
identity :id, :aliases => 'ID'
|
||||
attribute :name, :aliases => 'Name'
|
||||
attribute :server_class, :aliases => 'ServiceClass'
|
||||
attribute :cpu, :aliases => 'CPU'
|
||||
attribute :memory_mb, :aliases => 'MemoryMB'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/sakuracloud/models/compute/plan'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Plans < Fog::Collection
|
||||
model Fog::Compute::SakuraCloud::Plan
|
||||
|
||||
def all
|
||||
load service.list_plans.body['ServerPlans']
|
||||
end
|
||||
|
||||
def get(id)
|
||||
all.find { |f| f.id == id }
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Server < Fog::Model
|
||||
identity :id, :aliases => 'ID'
|
||||
attribute :name, :aliases => 'Name'
|
||||
attribute :server_plan, :aliases => 'ServerPlan'
|
||||
attribute :instance, :aliases => 'Instance'
|
||||
attribute :disks, :aliases => 'Disks'
|
||||
attribute :interfaces, :aliases => 'Interfaces'
|
||||
|
||||
def save
|
||||
requires :name, :server_plan
|
||||
data = service.create_server(@attributes[:name], @attributes[:server_plan]).body["Server"]
|
||||
merge_attributes(data)
|
||||
true
|
||||
end
|
||||
|
||||
def boot
|
||||
requires :id
|
||||
service.boot_server(@attributes[:id])
|
||||
end
|
||||
|
||||
def stop(force = false)
|
||||
requires :id
|
||||
service.stop_server(@attributes[:id], force)
|
||||
end
|
||||
|
||||
def delete(disks = [])
|
||||
requires :id
|
||||
service.delete_server(@attributes[:id], disks)
|
||||
true
|
||||
end
|
||||
alias_method :destroy, :delete
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,63 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/sakuracloud/models/compute/server'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Servers < Fog::Collection
|
||||
model Fog::Compute::SakuraCloud::Server
|
||||
|
||||
def all
|
||||
load service.list_servers.body['Servers']
|
||||
end
|
||||
|
||||
def get(id)
|
||||
all.find { |f| f.id == id }
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
def create(options = {})
|
||||
user = options[:user] || 'root'
|
||||
Fog::Logger.warning("Create Server")
|
||||
data = service.create_server(Fog::UUID.uuid, options[:serverplan]).body["Server"]
|
||||
server = service.servers.new
|
||||
server.merge_attributes(data)
|
||||
|
||||
if options[:volume]
|
||||
disk = create_and_attach_volume(server, options)
|
||||
server.reload
|
||||
end
|
||||
server.boot if options[:boot]
|
||||
server
|
||||
end
|
||||
|
||||
private
|
||||
def create_and_attach_volume(server, options)
|
||||
Fog::Logger.warning("Create Volume")
|
||||
sakuracloud_api_token = options[:sakuracloud_api_token] || Fog.credentials[:sakuracloud_api_token]
|
||||
sakuracloud_api_token_secret = options[:sakuracloud_api_token_secret] || Fog.credentials[:sakuracloud_api_token_secret]
|
||||
volume = Fog::Volume::SakuraCloud.new(:sakuracloud_api_token => sakuracloud_api_token, :sakuracloud_api_token_secret => sakuracloud_api_token_secret)
|
||||
disk = volume.disks.create :name => Fog::UUID.uuid,
|
||||
:plan => options[:volume][:diskplan].to_i,
|
||||
:source_archive => options[:volume][:sourcearchive].to_s
|
||||
Fog::Logger.warning("Waiting disk until available")
|
||||
disk.wait_for { availability == 'available' }
|
||||
volume.attach_disk(disk.id, server.id)
|
||||
disk_attached?(server, disk.id)
|
||||
Fog::Logger.warning("Modifing disk")
|
||||
volume.configure_disk(disk.id, options[:sshkey])
|
||||
disk
|
||||
end
|
||||
|
||||
def disk_attached?(server, disk_id)
|
||||
until server.disks.find {|s| disk_id.to_s}
|
||||
print '.'
|
||||
sleep 2
|
||||
server.reload
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class SshKey < Fog::Model
|
||||
identity :id, :aliases => 'ID'
|
||||
attribute :name, :aliases => 'Name'
|
||||
attribute :public_key, :aliases => 'PublicKey'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/sakuracloud/models/compute/ssh_key'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class SshKeys < Fog::Collection
|
||||
model Fog::Compute::SakuraCloud::SshKey
|
||||
|
||||
def all
|
||||
load service.list_ssh_keys.body['SSHKeys']
|
||||
end
|
||||
|
||||
def get(id)
|
||||
all.find { |f| f.id == id }
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Zone < Fog::Model
|
||||
identity :id, :aliases => 'ID'
|
||||
attribute :name, :aliases => 'Name'
|
||||
attribute :description, :aliases => 'Description'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/sakuracloud/models/compute/zone'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Zones < Fog::Collection
|
||||
model Fog::Compute::SakuraCloud::Zone
|
||||
|
||||
def all
|
||||
load service.list_zones.body['Zones']
|
||||
end
|
||||
|
||||
def get(id)
|
||||
all.find { |f| f.id == id }
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Archive < Fog::Model
|
||||
identity :id, :aliases => 'ID'
|
||||
attribute :name, :aliases => 'Name'
|
||||
attribute :size_mb, :aliases => 'SizeMB'
|
||||
attribute :plan, :aliases => 'Plan'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/sakuracloud/models/volume/archive'
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Archives < Fog::Collection
|
||||
model Fog::Volume::SakuraCloud::Archive
|
||||
|
||||
def all
|
||||
load service.list_archives.body['Archives']
|
||||
end
|
||||
|
||||
def get(id)
|
||||
all.find { |f| f.id == id }
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,37 +0,0 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Disk < Fog::Model
|
||||
identity :id, :aliases => 'ID'
|
||||
attribute :name, :aliases => 'Name'
|
||||
attribute :connection, :aliases => 'Connection'
|
||||
attribute :availability, :aliases => 'Availability'
|
||||
attribute :plan, :aliases => 'Plan'
|
||||
attribute :size_mb, :aliases => 'SizeMB'
|
||||
attribute :source_disk, :aliases => 'SourceDisk'
|
||||
attribute :source_archive, :aliases => 'SourceArchive'
|
||||
|
||||
def delete
|
||||
service.delete_disk(identity)
|
||||
true
|
||||
end
|
||||
alias_method :destroy, :delete
|
||||
|
||||
def save
|
||||
requires :name, :plan, :source_archive
|
||||
data = service.create_disk(@attributes[:name], @attributes[:plan], @attributes[:source_archive]).body["Disk"]
|
||||
merge_attributes(data)
|
||||
true
|
||||
end
|
||||
|
||||
def configure(sshkey_id)
|
||||
requires :id
|
||||
service.configure_disk(@attributes[:id], sshkey_id )
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,27 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/sakuracloud/models/volume/disk'
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Disks < Fog::Collection
|
||||
model Fog::Volume::SakuraCloud::Disk
|
||||
|
||||
def all
|
||||
load service.list_disks.body['Disks']
|
||||
end
|
||||
|
||||
def get(id)
|
||||
all.find { |f| f.id == id }
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
def delete(id)
|
||||
service.delete_disk(id)
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Plan < Fog::Model
|
||||
identity :id, :aliases => 'ID'
|
||||
attribute :name, :aliases => 'Name'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/sakuracloud/models/volume/plan'
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Plans < Fog::Collection
|
||||
model Fog::Volume::SakuraCloud::Plan
|
||||
|
||||
def all
|
||||
load service.list_plans.body['DiskPlans']
|
||||
end
|
||||
|
||||
def get(id)
|
||||
all.find { |f| f.id == id }
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,31 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def boot_server( id )
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:expects => [200],
|
||||
:method => 'PUT',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/server/#{id}/power"
|
||||
)
|
||||
true
|
||||
end
|
||||
end # Real
|
||||
|
||||
class Mock
|
||||
def boot_server( id )
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end # SakuraCloud
|
||||
end # Volume
|
||||
end # Fog
|
|
@ -1,41 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def create_server( name, serverplan )
|
||||
body = {
|
||||
"Server" => {
|
||||
"Name" => name,
|
||||
"ServerPlan" => {
|
||||
"ID" => serverplan.to_i
|
||||
},
|
||||
"ConnectedSwitches"=>[{"Scope"=>"shared", "BandWidthMbps"=>100}]
|
||||
}
|
||||
}
|
||||
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:expects => [201],
|
||||
:method => 'POST',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/server",
|
||||
:body => Fog::JSON.encode(body)
|
||||
)
|
||||
end
|
||||
end # Real
|
||||
|
||||
class Mock
|
||||
def create_server( name, serverplan )
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end # SakuraCloud
|
||||
end # Volume
|
||||
end # Fog
|
|
@ -1,33 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def delete_server( id, force = false, disks = [] )
|
||||
body = { "Force" => force, 'WithDisk' => disks }
|
||||
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:expects => [200],
|
||||
:method => 'DELETE',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/server/#{id}",
|
||||
:body => Fog::JSON.encode(body)
|
||||
)
|
||||
end
|
||||
end # Real
|
||||
|
||||
class Mock
|
||||
def delete_server( id, force = false, disks = [] )
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end # SakuraCloud
|
||||
end # Volume
|
||||
end # Fog
|
|
@ -1,46 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def list_plans(options = {})
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:method => 'GET',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/product/server"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_plans(options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"ServerPlans" =>
|
||||
[
|
||||
{"Index"=>0,
|
||||
"ID"=>1001,
|
||||
"Name"=>"プラン/1Core-1GB",
|
||||
"CPU"=>1,
|
||||
"MemoryMB"=>1024,
|
||||
"ServiceClass"=>"cloud/plan/1core-1gb",
|
||||
"Availability"=>"available"},
|
||||
{"Index"=>1,
|
||||
"ID"=>2001,
|
||||
"Name"=>"プラン/1Core-2GB",
|
||||
"CPU"=>1,
|
||||
"MemoryMB"=>2048,
|
||||
"ServiceClass"=>"cloud/plan/1core-2gb",
|
||||
"Availability"=>"available"}
|
||||
]
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def list_servers(options = {})
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:method => 'GET',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/server"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_servers(options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"Servers" =>
|
||||
[
|
||||
{"Index" => 0,
|
||||
"ID"=>112600055376,
|
||||
"Name"=>"foober1",
|
||||
"ServerPlan"=> {},
|
||||
"Instance"=> {},
|
||||
"Disks"=> []},
|
||||
{"Index" => 1,
|
||||
"ID"=>112600055377,
|
||||
"Name"=>"foober2",
|
||||
"ServerPlan"=> {},
|
||||
"Instance"=> {},
|
||||
"Disks"=> []}
|
||||
]
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def list_ssh_keys(options = {})
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:method => 'GET',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/sshkey"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_ssh_keys(options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"SSHKeys"=>
|
||||
[
|
||||
{"Index"=>0,
|
||||
"ID"=>"888888888888",
|
||||
"Name"=>"foobar1",
|
||||
"PublicKey"=>"ssh-rsa dummy"},
|
||||
{"Index"=>1,
|
||||
"ID"=>"999999999999",
|
||||
"Name"=>"foobar2",
|
||||
"PublicKey"=>"ssh-rsa dummy"}
|
||||
]
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def list_zones(options = {})
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:method => 'GET',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/zone"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_zones(options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"Zones" =>
|
||||
[
|
||||
{"Index"=>0,
|
||||
"ID"=>31001,
|
||||
"Name"=>"is1a",
|
||||
"Description"=>"石狩第1ゾーン"},
|
||||
{"Index"=>1,
|
||||
"ID"=>31002,
|
||||
"Name"=>"is1b",
|
||||
"Description"=>"石狩第2ゾーン"}
|
||||
]
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,37 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def stop_server( id, force = false )
|
||||
if force
|
||||
body = { "Force" => true }
|
||||
else
|
||||
body = {}
|
||||
end
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:expects => [200,202],
|
||||
:method => 'DELETE',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/server/#{id}/power",
|
||||
:body => Fog::JSON.encode(body)
|
||||
)
|
||||
true
|
||||
end
|
||||
end # Real
|
||||
|
||||
class Mock
|
||||
def stop_server( id, force = false )
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.body = {
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end # SakuraCloud
|
||||
end # Volume
|
||||
end # Fog
|
|
@ -1,30 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def attach_disk( disk_id, server_id )
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:expects => [200],
|
||||
:method => 'PUT',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/disk/#{disk_id.to_s}/to/server/#{server_id.to_s}"
|
||||
)
|
||||
end
|
||||
end # Real
|
||||
|
||||
class Mock
|
||||
def attach_disk( disk_id, server_id )
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end # SakuraCloud
|
||||
end # Volume
|
||||
end # Fog
|
|
@ -1,35 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def configure_disk( disk_id, sshkey_id )
|
||||
body = {
|
||||
"SSHKey" => {"ID" => sshkey_id.to_s }
|
||||
}
|
||||
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:expects => [200],
|
||||
:method => 'PUT',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/disk/#{disk_id.to_s}/config",
|
||||
:body => Fog::JSON.encode(body)
|
||||
)
|
||||
end
|
||||
end # Real
|
||||
|
||||
class Mock
|
||||
def configure_disk( disk_id, sshkey_id )
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end # SakuraCloud
|
||||
end # Volume
|
||||
end # Fog
|
|
@ -1,43 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def create_disk( name, plan, sourcearchive )
|
||||
body = {
|
||||
"Disk" => {
|
||||
"Name" => name,
|
||||
"SourceArchive" => {
|
||||
"ID" => sourcearchive.to_s
|
||||
},
|
||||
"Plan" => {
|
||||
"ID" => plan.to_i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:expects => [202],
|
||||
:method => 'POST',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/disk",
|
||||
:body => Fog::JSON.encode(body)
|
||||
)
|
||||
end
|
||||
end # Real
|
||||
|
||||
class Mock
|
||||
def create_disk( name, plan, sourcearchive )
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.body = {
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end # SakuraCloud
|
||||
end # Volume
|
||||
end # Fog
|
|
@ -1,30 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def delete_disk( id )
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:expects => [200],
|
||||
:method => 'DELETE',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/disk/#{id}"
|
||||
)
|
||||
end
|
||||
end # Real
|
||||
|
||||
class Mock
|
||||
def delete_disk( id )
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end # SakuraCloud
|
||||
end # Volume
|
||||
end # Fog
|
|
@ -1,46 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def list_archives(options = {})
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:method => 'GET',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/archive"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_archives(options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"Archives" =>
|
||||
[
|
||||
{"Index"=>0,
|
||||
"ID"=>112500514887,
|
||||
"Name"=>"CentOS 5.10 64bit (基本セット)",
|
||||
"Availability"=>"available",
|
||||
"SizeMB"=>20480,
|
||||
"Plan"=>{"ID"=>2, "StorageClass"=>"iscsi1204", "Name"=>"標準プラン"}
|
||||
},
|
||||
{"Index"=>1,
|
||||
"ID"=>112500571575,
|
||||
"Name"=>"CentOS 6.5 64bit (基本セット)",
|
||||
"Availability"=>"available",
|
||||
"SizeMB"=>102400,
|
||||
"Plan"=>{"ID"=>2, "StorageClass"=>"iscsi1204", "Name"=>"標準プラン"}
|
||||
}
|
||||
]
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,50 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def list_disks(options = {})
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:method => 'GET',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/disk"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_disks(options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"Disks" =>
|
||||
[
|
||||
{"Index" => 0,
|
||||
"ID" =>112600053890,
|
||||
"Name" =>"foober1",
|
||||
"Connection" => "virtio",
|
||||
"Availability"=>"available",
|
||||
"SizeMB"=>20480,
|
||||
"Plan"=> {},
|
||||
"SourceDisk" => nil,
|
||||
"SourceArchive" => {}},
|
||||
{"Index" => 1,
|
||||
"ID" =>112600053891,
|
||||
"Name" =>"foober2",
|
||||
"Connection" => "virtio",
|
||||
"Availability"=>"available",
|
||||
"SizeMB"=>20480,
|
||||
"Plan"=> {},
|
||||
"SourceDisk" => nil,
|
||||
"SourceArchive" => {}}
|
||||
]
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud
|
||||
class Real
|
||||
def list_plans(options = {})
|
||||
request(
|
||||
:headers => {
|
||||
'Authorization' => "Basic #{@auth_encord}"
|
||||
},
|
||||
:method => 'GET',
|
||||
:path => "#{Fog::SakuraCloud::SAKURACLOUD_API_ENDPOINT}/product/disk"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_plans(options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"DiskPlans" =>
|
||||
[
|
||||
{"Index"=>0,
|
||||
"ID"=>4,
|
||||
"Name"=>"SSDプラン",
|
||||
"Availability"=>"available"},
|
||||
{"Index"=>1,
|
||||
"ID"=>2,
|
||||
"Name"=>"標準プラン",
|
||||
"Availability"=>"available"}
|
||||
]
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,88 +0,0 @@
|
|||
require 'fog/sakuracloud'
|
||||
require 'fog/volume'
|
||||
|
||||
module Fog
|
||||
module Volume
|
||||
class SakuraCloud < Fog::Service
|
||||
requires :sakuracloud_api_token
|
||||
requires :sakuracloud_api_token_secret
|
||||
|
||||
recognizes :sakuracloud_api_url
|
||||
|
||||
model_path 'fog/sakuracloud/models/volume'
|
||||
model :archive
|
||||
collection :archives
|
||||
model :plan
|
||||
collection :plans
|
||||
model :disk
|
||||
collection :disks
|
||||
|
||||
request_path 'fog/sakuracloud/requests/volume'
|
||||
request :list_disks
|
||||
request :list_plans
|
||||
request :create_disk
|
||||
request :configure_disk
|
||||
request :attach_disk
|
||||
request :delete_disk
|
||||
request :list_archives
|
||||
|
||||
class Real
|
||||
def initialize(options = {})
|
||||
@auth_encord = Base64.strict_encode64([
|
||||
options[:sakuracloud_api_token],
|
||||
options[:sakuracloud_api_token_secret]
|
||||
].join(':'))
|
||||
Fog.credentials[:sakuracloud_api_token] = options[:sakuracloud_api_token]
|
||||
Fog.credentials[:sakuracloud_api_token_secret] = options[:sakuracloud_api_token_secret]
|
||||
|
||||
@sakuracloud_api_url = options[:sakuracloud_api_url] || 'https://secure.sakura.ad.jp'
|
||||
|
||||
@connection = Fog::Core::Connection.new(@sakuracloud_api_url)
|
||||
end
|
||||
|
||||
def request(params)
|
||||
response = parse @connection.request(params)
|
||||
response
|
||||
end
|
||||
|
||||
private
|
||||
def parse(response)
|
||||
return response if response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {
|
||||
:disks => [],
|
||||
:plans => [],
|
||||
:archives => []
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@data = nil
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@sakuracloud_api_token = options[:sakuracloud_api_token]
|
||||
@sakuracloud_api_token_secret = options[:sakuracloud_api_token_secret]
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data[@sakuracloud_api_token]
|
||||
self.class.data[@sakuracloud_api_token_secret]
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.data.delete(@sakuracloud_api_token)
|
||||
self.class.data.delete(@sakuracloud_api_token_secret)
|
||||
end
|
||||
end
|
||||
end #SakuraCloud
|
||||
end #Volume
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
def volume_service
|
||||
Fog::Volume[:sakuracloud]
|
||||
end
|
||||
|
||||
def compute_service
|
||||
Fog::Compute[:sakuracloud]
|
||||
end
|
|
@ -1,32 +0,0 @@
|
|||
# coding: utf-8
|
||||
Shindo.tests('Fog::Compute[:sakuracloud] | list_plans request', ['sakuracloud', 'compute']) do
|
||||
|
||||
@plan_format = {
|
||||
'Index' => Integer,
|
||||
'ID' => Integer,
|
||||
'Name' => String,
|
||||
'CPU' => Integer,
|
||||
'MemoryMB' => Integer,
|
||||
'Availability' => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#list_plans') do
|
||||
serverplans = compute_service.list_plans
|
||||
test 'returns a Hash' do
|
||||
serverplans.body.is_a? Hash
|
||||
end
|
||||
if Fog.mock?
|
||||
tests('ServerPlans').formats(@plan_format, false) do
|
||||
serverplans.body['ServerPlans'].first
|
||||
end
|
||||
else
|
||||
returns(200) { serverplans.status }
|
||||
returns(false) { serverplans.body.empty? }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,46 +0,0 @@
|
|||
# coding: utf-8
|
||||
Shindo.tests('Fog::Compute[:sakuracloud] | list_servers request', ['sakuracloud', 'compute']) do
|
||||
|
||||
@servers_format = {
|
||||
'Index' => Integer,
|
||||
'ID' => Integer,
|
||||
'Name' => String,
|
||||
'ServerPlan' => Hash,
|
||||
'Instance' => Hash,
|
||||
'Disks' => Array
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#list_servers') do
|
||||
servers = compute_service.list_servers
|
||||
test 'returns a Hash' do
|
||||
servers.body.is_a? Hash
|
||||
end
|
||||
if Fog.mock?
|
||||
tests('Servers').formats(@servers_format, false) do
|
||||
servers.body['Servers'].first
|
||||
end
|
||||
else
|
||||
returns(200) { servers.status }
|
||||
returns(true) { servers.body.is_a? Hash }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Shindo.tests('Fog::Compute[:sakuracloud] | create_servers request', ['sakuracloud', 'compute']) do
|
||||
tests('success') do
|
||||
tests('#create_servers') do
|
||||
servers = compute_service.create_server('foobar', 2001)
|
||||
test 'returns a Hash' do
|
||||
servers.body.is_a? Hash
|
||||
end
|
||||
|
||||
unless Fog.mock?
|
||||
returns(201) { servers.status }
|
||||
returns(true) { servers.body.is_a? Hash }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
# coding: utf-8
|
||||
Shindo.tests('Fog::Compute[:sakuracloud] | list_ssh_keys request', ['sakuracloud', 'compute']) do
|
||||
|
||||
@sshkey_format = {
|
||||
'Index' => Integer,
|
||||
'ID' => String,
|
||||
'Name' => String,
|
||||
'PublicKey' => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#list_ssh_keys') do
|
||||
sshkeys = compute_service.list_ssh_keys
|
||||
test 'returns a Hash' do
|
||||
sshkeys.body.is_a? Hash
|
||||
end
|
||||
if Fog.mock?
|
||||
tests('SSHKeys').formats(@sshkey_format, false) do
|
||||
sshkeys.body['SSHKeys'].first
|
||||
end
|
||||
else
|
||||
returns(200) { sshkeys.status }
|
||||
returns(false) { sshkeys.body.empty? }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
# coding: utf-8
|
||||
Shindo.tests('Fog::Compute[:sakuracloud] | list_zones request', ['sakuracloud', 'compute']) do
|
||||
|
||||
@zone_format = {
|
||||
'Index' => Integer,
|
||||
'ID' => Integer,
|
||||
'Name' => String,
|
||||
'Description' => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#list_zones') do
|
||||
zones = compute_service.list_zones
|
||||
test 'returns a Hash' do
|
||||
zones.body.is_a? Hash
|
||||
end
|
||||
if Fog.mock?
|
||||
tests('Zones').formats(@zone_format, false) do
|
||||
zones.body['Zones'].first
|
||||
end
|
||||
else
|
||||
returns(200) { zones.status }
|
||||
returns(false) { zones.body.empty? }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,31 +0,0 @@
|
|||
# coding: utf-8
|
||||
Shindo.tests('Fog::Volume[:sakuracloud] | list_archives request', ['sakuracloud', 'volume']) do
|
||||
|
||||
@archive_format = {
|
||||
'Index' => Integer,
|
||||
'ID' => Integer,
|
||||
'Name' => String,
|
||||
'SizeMB' => Integer,
|
||||
'Plan' => Hash
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#list_archives') do
|
||||
archives = volume_service.list_archives
|
||||
test 'returns a Hash' do
|
||||
archives.body.is_a? Hash
|
||||
end
|
||||
if Fog.mock?
|
||||
tests('Archives').formats(@archive_format, false) do
|
||||
archives.body['Archives'].first
|
||||
end
|
||||
else
|
||||
returns(200) { archives.status }
|
||||
returns(false) { archives.body.empty? }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,47 +0,0 @@
|
|||
# coding: utf-8
|
||||
Shindo.tests('Fog::Volume[:sakuracloud] | list_disks request', ['sakuracloud', 'volume']) do
|
||||
|
||||
@disks_format = {
|
||||
'Index' => Integer,
|
||||
'ID' => Integer,
|
||||
'Name' => String,
|
||||
'Connection' => String,
|
||||
'Availability' => String,
|
||||
'SizeMB' => Integer,
|
||||
'Plan' => Hash
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#list_disks') do
|
||||
disks = volume_service.list_disks
|
||||
test 'returns a Hash' do
|
||||
disks.body.is_a? Hash
|
||||
end
|
||||
if Fog.mock?
|
||||
tests('Disks').formats(@disks_format, false) do
|
||||
disks.body['Disks'].first
|
||||
end
|
||||
else
|
||||
returns(200) { disks.status }
|
||||
returns(true) { disks.body.is_a? Hash }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Shindo.tests('Fog::Volume[:sakuracloud] | create_disks request', ['sakuracloud', 'volume']) do
|
||||
tests('success') do
|
||||
tests('#create_disks') do
|
||||
disks = volume_service.create_disk('foobar', 4, 112500463685)
|
||||
test 'returns a Hash' do
|
||||
disks.body.is_a? Hash
|
||||
end
|
||||
|
||||
unless Fog.mock?
|
||||
returns(202) { disks.status }
|
||||
returns(true) { disks.body.is_a? Hash }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
# coding: utf-8
|
||||
Shindo.tests('Fog::Volume[:sakuracloud] | list_plans request', ['sakuracloud', 'volume']) do
|
||||
|
||||
@plan_format = {
|
||||
'Index' => Integer,
|
||||
'ID' => Integer,
|
||||
'Name' => String,
|
||||
'Availability' => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#list_plans') do
|
||||
diskplans = volume_service.list_plans
|
||||
test 'returns a Hash' do
|
||||
diskplans.body.is_a? Hash
|
||||
end
|
||||
if Fog.mock?
|
||||
tests('DiskPlans').formats(@plan_format, false) do
|
||||
diskplans.body['DiskPlans'].first
|
||||
end
|
||||
else
|
||||
returns(200) { diskplans.status }
|
||||
returns(false) { diskplans.body.empty? }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue