-
-
Notifications
You must be signed in to change notification settings - Fork 6
Getting started for SakuraCloud
- Product Information: http://cloud.sakura.ad.jp/
- API Reference(1.1): http://developer.sakura.ad.jp/cloud/api/1.1/
- API TOKEN
- API TOKEN SECRET
You can retreave them from dashboard.
Service | Class | Description |
---|---|---|
Volume(disk) | Fog::Volume::SakuraCloud | Block device for server. |
Compute | Fog::Compute::SakuraCloud | Server. |
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.
Usage for SakuraCloud Services.
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]
use volume.plans
.
> volume.plans
=> [ <Fog::Volume::SakuraCloud::Plan
id=4,
name="SSDプラン"
>,
<Fog::Volume::SakuraCloud::Plan
id=2,
name="標準プラン"
>]
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 --
use volume.disks.create
with :name
, :plan
(Plan id) and :source_archive
(id, optional)
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}
>
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}
>
use volume.disks.delete('Disk_id')
> volume.disks.delete('112600053837')
=> true
or execute delete method for disk.
> volume.disks.first.delete
=> true
> volume.disks.each {|d| d.delete}
Initailize Compute service.
require 'fog'
compute = Fog::Compute::SakuraCloud.new(
:sakuracloud_api_token => 'YOUR_API_TOKEN',
:sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET'
)
use compute.ssh_keys
> compute.ssh_keys
=> [ <Fog::Compute::SakuraCloud::SshKey
id="11260003****",
name="sawanobori",
PublicKey="ssh-rsa ***********************"
>]
Work with Volume service.
use configure
method with SSH Key id.
> volume.disks.first.configure(11260003****)
=> true
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]
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 --
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ゾーン"
>]
use volume.servers.create
with :name
, :serverplan
(Plan id)
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}]
>
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}]
>]
execute boot/stop method for server.
> compute.servers.first.boot
=> true
> compute.servers.first.stop
=> true
force stop
> compute.servers.first.stop(true)
=> true