Skip to content

Getting started for SakuraCloud

Roy Quader edited this page Jan 20, 2016 · 26 revisions

Getting started for SakuraCloud

For 1.7.x or later.

Table of Contents

Created by gh-md-toc

Links

Requirements

  • API TOKEN
  • API TOKEN SECRET

You can retrieve them from the dashboard.

Resources

Service Class Description
Volume(disk) Fog::Volume::SakuraCloud Block device for server.
Compute Fog::Compute::SakuraCloud Server.
Network Fog::Network::SakuraCloud Manage swithces and routers(Internet resource), interfaces.
DNS Fog::DNS::SakuraCloud Manage DNS(CommonServiceItem resource).
Script Fog::SakuraCloud::Script Manage Startup Scripts(Notes).

Simple start

Initial boot from template with ssh key.

require 'fog/sakuracloud'
compute = Fog::Compute::SakuraCloud.new(
  :sakuracloud_api_token => 'YOUR_API_TOKEN',
  :sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET'
)


server = compute.servers.create(
  :name  => 'fogserver',
  :sshkey => '11260003****',          # Your SSH Key id
  :serverplan => '2001',              # Server Type
  :volume => {
    :diskplan => 4,                   # Type SSD
    :sourcearchive => '112700660567'  # Ubuntu14.04
  },
  :boot => true
)

## With Startup Script
server = compute.servers.create(
  :name  => 'fogserver',
  :sshkey => '11260003****',          # Your SSH Key id
  :startup_sctipt => ['11260003****'],# Array or String
  :serverplan => '2001',              # Server Type
  :volume => {
    :diskplan => 4,                   # Type SSD
    :sourcearchive => '112700660567'  # Ubuntu14.04
  },
  :boot => true
)

You can login or integrate with configuration management tools to server at once.

Services

Usage for SakuraCloud Services.

Volume(disk) Service

Initialize Volume service.

require 'fog/sakuracloud'
volume = Fog::Volume::SakuraCloud.new(
  :sakuracloud_api_token => 'YOUR_API_TOKEN',
  :sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET',
  :api_zone => "tk1a"   # optional, is1b by default
)

or initialize 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/sakuracloud'
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}
  >

With specific SizeMB.

disk = volume.disks.create :name => 'foobar2',
                           :plan  => 2,  # Type Standard
                           :source_archive => 112500463685, # Ubuntu12.04
                           :size_mb => 40960

It creates Standard 40960MB disk.

=>   <Fog::Volume::SakuraCloud::Disk
    id="112700978388",
    name="foobar2",
    connection="ide",
    availability="migrating",
    plan={"ID"=>2, "StorageClass"=>"iscsi1204", "Name"=>"標準プラン"},
    size_mb=40960,
    source_disk=nil,
    source_archive={"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}
  >

Note: valid SizeMBs by Plans
SSD: 40960,61440,81920,102400,256000,512000,768000,1048576,2097152,4194304 標準: 20480,102400,256000,512000

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}

Attach Disk to a server

use disk.attach('Server_id')

> disk = volume.disks.get('112700978388')
=>   <Fog::Volume::SakuraCloud::Disk
    id="112700978388",
    name="foobar2",
    connection="ide",
    availability="available",
    plan={"ID"=>2, "StorageClass"=>"iscsi1204", "Name"=>"標準プラン"},
    size_mb=40960,
    source_disk=nil,
    source_archive={"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}
  >

> disk.attach('112700978415')
=> true

Associate IP address to disk

use disk.associate_ip('<ipaddress>', <netmask>, 'defaultroute')

> disk = volume.disks.first
disk.associate_ip('133.242.xxxx.xxx', 28, '133.242.xxx.xxx')
=> true

SSH Key Service (Part of the Compute Service)

Initialize Compute service.

require 'fog/sakuracloud'
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

Network Service

Initialize Network service.

require 'fog/sakuracloud'
network = Fog::Network::SakuraCloud.new(
  :sakuracloud_api_token => 'YOUR_API_TOKEN',
  :sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET',
  :api_zone => "tk1a"   # optional, is1b by default
)

or initialize with Fog.credentials

Fog.credentials[:sakuracloud_api_token] = 'YOUR_API_TOKEN'
Fog.credentials[:sakuracloud_api_token_secret] = 'YOUR_API_TOKEN_SECRET'

network = Fog::Network[:sakuracloud]

Listing switches

use network.switches.

 network.switches
=> [  <Fog::Network::SakuraCloud::Switch
    id="112600708440",
    name="foosw01",
    description="",
    server_count=0,
    appliance_count=0,
    subnets=[],
    ipv6nets=[],
    internet=nil,
    bridge=nil
  >,
   <Fog::Network::SakuraCloud::Switch
    id="112600708441",
    name="foosw02",
    description="",
    server_count=0,
    appliance_count=0,
    subnets=[],
    ipv6nets=[],
    internet=nil,
    bridge=nil
  >,
   <Fog::Network::SakuraCloud::Switch
    id="112600708443",
    name="foort02",
    description="",
    server_count=0,
    appliance_count=0,
    subnets=[{"ID"=>1422, "NetworkAddress"=>"133.242.241.240", "NetworkMaskLen"=>28, "DefaultRoute"=>"133.242.241.241", "NextHop"=>nil, "StaticRoute"=>nil, "ServiceClass"=>"cloud/global-ipaddress-v4/28", "IPAddresses"=>{"Min"=>"133.242.241.244", "Max"=>"133.242.241.254"}, "Internet"=>{"ID"=>"112600708442", "Name"=>"foort02", "BandWidthMbps"=>100, "ServiceClass"=>"cloud/internet/router/100m"}}],
    ipv6nets=[],
    internet={"ID"=>"112600708442", "Name"=>"foort02", "BandWidthMbps"=>100, "Scope"=>"user", "ServiceClass"=>"cloud/internet/router/100m"},
    bridge=nil
  >]

Listing routers(Internet resource)

use network.routers.

> network.routers
=> [  <Fog::Network::SakuraCloud::Router
    id="112600708442",
    name="foort02",
    description="",
    server_count=nil,
    appliance_count=nil,
    subnets=nil,
    ipv6nets=nil,
    internet=nil,
    bridge=nil,
    networkmasklen=nil
  >]

Create switch

use network.switches.create with ``:name`.

switch = network.switches.create(:name => 'foosw01')

It creates switch.

=>   <Fog::Network::SakuraCloud::Switch
    id="112600708440",
    name="foosw01",
    description="",
    server_count=0,
    appliance_count=0,
    subnets=[],
    ipv6nets=[],
    internet=nil,
    bridge=nil
  >

Create router

use network.routers.create with ``:nameand:networkmasklen`.

router = network.routers.create(:name => 'foort02', :networkmasklen => 28)

It creates router with subnet and internet access.

=>   <Fog::Network::SakuraCloud::Router
    id="112600708484",
    name="foort02",
    description="",
    server_count=0,
    appliance_count=0,
    subnets=[{"ID"=>1429, "NetworkAddress"=>"133.242.241.0", "NetworkMaskLen"=>28, "DefaultRoute"=>"133.242.241.1", "NextHop"=>nil, "StaticRoute"=>nil, "ServiceClass"=>"cloud/global-ipaddress-v4/28", "IPAddresses"=>{"Min"=>"133.242.241.4", "Max"=>"133.242.241.14"}, "Internet"=>{"ID"=>"112600708483", "Name"=>"foort02", "BandWidthMbps"=>100, "ServiceClass"=>"cloud/internet/router/100m"}}],
    ipv6nets=[],
    internet={"ID"=>"112600708483", "Name"=>"foort02", "BandWidthMbps"=>100, "Scope"=>"user", "ServiceClass"=>"cloud/internet/router/100m"},
    bridge=nil,
    networkmasklen=28
  >

Delete switch

use network.switches.delete('Switch_id')

> network.switches.delete('112600053837')

=> true

or execute delete method for switch.

> network.switches.first.delete

=> true

Delete Router

use network.routers.delete('Router_ID')

Note: Routers are shown by switches list. But you can't delete a router from switch resource. Use routers.

> network.routers.delete('112600053837')

=> true

or execute delete method for router.

> network.routers.first.delete

=> true

Change BandWidth of Router

Notice: This operation will changes Router ID.

> router = network.routers.get('112701085218')
> router.change_bandwidth(1000)
=>   <Fog::Network::SakuraCloud::Router
    id="112701094436",
    name="foort02",
    description="",
    networkmasklen=28,
    bandwidthmbps=1000,
    switch={"ID"=>"112701094433", "Name"=>"foort02", "Scope"=>"user", "UserSubnet"=>nil, "HybridConnection"=>nil, "Subnets"=>[{"ID"=>1329, "NetworkAddress"=>"27.133.138.160", "NetworkMaskLen"=>28, "DefaultRoute"=>"27.133.138.161", "NextHop"=>nil, "StaticRoute"=>nil}], "IPv6Nets"=>[], "Bridge"=>nil}
  >


> router.id
=> 112701094436  ## ID has changed.

Collect traffic amount of Router

use collect_monitor

> router = network.routers.get('112701085218')
> router.collect_monitor
=> {"2015-12-17T14:05:00+09:00"=>{"In"=>nil, "Out"=>nil},
 "2015-12-17T14:10:00+09:00"=>{"In"=>nil, "Out"=>nil},
 "2015-12-17T14:15:00+09:00"=>{"In"=>nil, "Out"=>nil},
 "2015-12-17T14:20:00+09:00"=>{"In"=>nil, "Out"=>nil},
 "2015-12-17T14:25:00+09:00"=>{"In"=>nil, "Out"=>nil},
 "2015-12-17T14:30:00+09:00"=>{"In"=>nil, "Out"=>nil},
 "2015-12-17T14:35:00+09:00"=>{"In"=>nil, "Out"=>nil},
...

filter by start and end.

> router.collect_monitor('2015-12-17T18:45:00+09:00', '2015-12-17T19:00:00+09:00')
=> {"2015-12-17T18:50:00+09:00"=>{"In"=>nil, "Out"=>nil},
 "2015-12-17T18:55:00+09:00"=>{"In"=>nil, "Out"=>nil},
 "2015-12-17T19:00:00+09:00"=>{"In"=>nil, "Out"=>nil},
 "2015-12-17T19:05:00+09:00"=>{"In"=>nil, "Out"=>nil}}

## get values after 24 hours of the start time
> router.collect_monitor("2015-12-17T18:50:00+09:00")

## from 24hours before end
> router.collect_monitor(nil, '2015-12-17T19:00:00+09:00')

Listing interfaces

use network.interfaces.

> network.interfaces
=> [  <Fog::Network::SakuraCloud::Interface
    id="112700797771",
    macaddress="9C:A3:BA:30:06:00",
    ipaddress=nil,
    user_ipaddress=nil,
    switch={"ID"=>"112700797602"},
    server={"ID"=>"112700797610"}
  >]

Add interface to server

use network.interfaces.regist_onto_server.

must need Server-ID to create new interface.

> network.interfaces.regist_onto_server('112700797610')
=>   <Fog::Network::SakuraCloud::Interface
    id="112700799690",
    macaddress="9C:A3:BA:30:B6:DD",
    ipaddress=nil,
    user_ipaddress=nil,
    switch=nil,
    server={"ID"=>"112700797610"}
  >

Connect interface to Switch

use network.interfaces.connect_to_switch with interface-ID and switch-ID.

> network.interfaces.connect_to_switch('112700799690', '112700797600')
=>   <Fog::Network::SakuraCloud::Interface
    id="112700799690",
    macaddress="9C:A3:BA:30:B6:DD",
    ipaddress=nil,
    user_ipaddress=nil,
    switch={"ID"=>"112700797600"},
    server={"ID"=>"112700797610"}
  >

or, use Interface#connect_to_switch.

> interface = network.interfaces.get('112700799690')
> interface.connect_to_switch('112700797600')
=> true

Delete interface

use network.interfaces.delete.

> network.interfaces.delete('112700799690')
=> true

or, use Interface#delete

> interface = network.interfaces.get('112700799690')
> interface.delete
=> true

Compute Service

Initialize Compute service.

require 'fog/sakuracloud'
compute = Fog::Compute::SakuraCloud.new(
  :sakuracloud_api_token => 'YOUR_API_TOKEN',
  :sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET',
  :api_zone => "tk1a"   # optional, is1b by default
)

or initialize with Fog.credentials

Fog.credentials[:sakuracloud_api_token] = 'YOUR_API_TOKEN'
Fog.credentials[:sakuracloud_api_token_secret] = 'YOUR_API_TOKEN_SECRET'

compute = 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}]
  >
Example: Create server with specific switch connection.
server = compute.servers.create :name => 'foobar',
                                :serverplan  => 2001,
                                :switch => '1126000xxxx'

It creates server with specific switch.

You can pass multiple connection with comma separated string like '1126000xxxx,1126000xxxx,1126000xxxx'.

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

Delete Servers

execute delete/destroy method for server. The server must be stopped before delete.

> compute.servers.first.delete

=> true

force delete with disk.

> compute.servers.first.delete(true, ["DISK_ID", "DISK_ID"])

=> true

Script Service

Initialize Script service.

require 'fog/sakuracloud'
script = Fog::SakuraCloud::Script.new(
  :sakuracloud_api_token => 'YOUR_API_TOKEN',
  :sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET',
  :api_zone => "tk1a"   # optional, is1b by default
)

or initialize with Fog.credentials

Fog.credentials[:sakuracloud_api_token] = 'YOUR_API_TOKEN'
Fog.credentials[:sakuracloud_api_token_secret] = 'YOUR_API_TOKEN_SECRET'

script = Fog::SakuraCloud[:script]

Listing notes

use script.notes.

> script.notes

=> [  <Fog::SakuraCloud::Script::Note
    id="112500569786",
    name="LAMP",
    note_class="shell",
    scope="shared",
    content="#!/bin/bash\n\n# @sacloud-once\n\n# @sacloud-desc Apache, PHP, MySQLをインストールします。\n# @sacloud-desc (このスクリプトは、CentOS6.XもしくはScientific Linux6.Xでのみ動作します)\n# @sacloud-require-archive distro-centos distro-ver-6.*\n# @sacloud-require-archive distro-sl distro-ver-6.*\n\n#---------START OF iptables---------#\ncat <<'EOT' > /etc/sysconfig/iptables\n*filter\n:INPUT DROP [0:0]\n:FORWARD DROP [0:0]\n:OUTPUT ACCEPT [0:0]\n:fail2ban-SSH - [0:0]\n-A INPUT -p tcp -m multiport --dports 22 -j fail2ban-SSH \n-A INPUT -p TCP -m state --state NEW ! --syn -j DROP\n-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT \n-A INPUT -p icmp -j ACCEPT \n-A INPUT -i lo -j ACCEPT \n-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT \n-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT \n-A INPUT -p udp --sport 123 --dport 123 -j ACCEPT\n-A INPUT -p udp --sport 53 -j ACCEPT\n-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT \n-A fail2ban-SSH -j RETURN\nCOMMIT\nEOT\nservice iptables restart\n#---------END OF iptables---------#\n#---------START OF LAMP---------#\nyum -y install expect httpd-devel mod_ssl php-devel php-pear mysql-server php-mbstring php-xml php-gd php-mysql|| exit 1\nservice httpd status >/dev/null 2>&1 || service httpd start\n\nfor i in {1..5}; do\nsleep 1\nservice httpd status && break\n[ \"$i\" -lt 5 ] || exit 1\ndone\nchkconfig httpd on || exit 1\n\nservice mysqld status >/dev/null 2>&1 || service mysqld start\nfor i in {1..5}; do\nsleep 1\nservice mysqld status && break\n[ \"$i\" -lt 5 ] || exit 1\ndone\nchkconfig mysqld on || exit 1\n\nNEWMYSQLPASSWORD=`mkpasswd -l 32 -d 9 -c 9 -C 9 -s 0 -2`\n\n/usr/bin/mysqladmin -u root password \"$NEWMYSQLPASSWORD\" || exit 1\n\ncat <<EOT > /root/.my.cnf\n[client]\nhost     = localhost\nuser     = root\npassword = $NEWMYSQLPASSWORD\nsocket   = /var/lib/mysql/mysql.sock\nEOT\nchmod 600 /root/.my.cnf\n#---------END OF LAMP---------#",
    description="Apache, PHP, MySQLをインストールします。\n(このスクリプトは、CentOS6.XもしくはScientific Linux6.Xでのみ動作します)",
    remark={"Require"=>{"Archive"=>{"Tags"=>[["distro-centos", "distro-ver-6.*"], ["distro-sl", "distro-ver-6.*"]]}}},
    availability="available",
    icon=nil
  >,
   <Fog::SakuraCloud::Script::Note
    id="112500569787",
    name="WordPress",
    note_class="shell",
    scope="shared",
-- snip --

For example, user scope only.

> script.notes.find {|note| note.scope == "user"}

=>   <Fog::SakuraCloud::Script::Note
    id="112700759851",
    name="foobar",
    note_class="shell",
    scope="user",
    content="/bin/true",
    description=nil,
    remark=nil,
    availability="available",
    icon=nil
  >

Get by ID.

> script.notes.get('112700760023')

=>   <Fog::SakuraCloud::Script::Note
    id="112700760023",
    name="barfoo",
    note_class="shell",
    scope="user",
    content="#!/bin/bash\n echo 'this is startup script.'",
    description="",
    remark=nil,
    availability="available",
    icon=nil
  >

Create new note

use script.notes.create with :name, :content.

> sc = script.notes.create :name => 'barfoo',
                                :content  => "#!/bin/bash\n echo 'this is startup script.'"

Update existing note

use search by id and save.

> sc = script.notes.select {|note| note.id == '112700760015'}.first

=>   <Fog::SakuraCloud::Script::Note
    id="112700760015",
    name="barfoo",
    note_class="shell",
    scope="user",
    content="#!/bin/bash\n echo 'this is startup script.'",
    description="",
    remark=nil,
    availability="available",
    icon=nil
  >


> sc.name = "foofoo"
> sc.save
=> true

Delete Note

use script.notes.delete('Note_ID')

> script.notes.delete('112600053837')

=> true

or execute delete method for note.

> script.notes.first.delete

=> true

Register Startup Script to disk.

Work with Volume service.

use register_script method with Note id.

Example
# single script
> volume.disks.first.register_script("11260003****")

=> true

# multiple scripts
> volume.disks.first.register_script(["11260003****", "11260004****"])
>>>>>>> 2c3b32e19152fb5fce209e96ccedd80f2c6a2320:Getting-started-for-SakuraCloud.md

=> true

DNS Service

Initialize DNS service.

require 'fog/sakuracloud'
dns = Fog::DNS::SakuraCloud.new(
  :sakuracloud_api_token => 'YOUR_API_TOKEN',
  :sakuracloud_api_token_secret => 'YOUR_API_TOKEN_SECRET',
  :api_zone => "tk1a"   # optional, is1b by default
)

or initialize with Fog.credentials

Fog.credentials[:sakuracloud_api_token] = 'YOUR_API_TOKEN'
Fog.credentials[:sakuracloud_api_token_secret] = 'YOUR_API_TOKEN_SECRET'

dns = Fog::DNS[:sakuracloud]

Listing zones

use dns.zones.

> dns.zones
=> [  <Fog::DNS::SakuraCloud::Zone
    id="112700799891",
    name="sawanoboly4.net",
    description=nil,
    status={"Zone"=>"sawanoboly4.net", "NS"=>["ns1.gslb2.sakura.ne.jp", "ns2.gslb2.sakura.ne.jp"]},
    settings={"DNS"=>{"ResourceRecordSets"=>[{"Name"=>"www", "Type"=>"A", "RData"=>"192.168.1.2"}]}},
    tags=[]
  >]
...

zone has reader methods #zone, #nameservers and #rr_sets.

> dns.zones.first.zone
=> "sawanoboly4.net"

> dns.zones.first.nameservers
=> ["ns1.gslb2.sakura.ne.jp", "ns2.gslb2.sakura.ne.jp"]

> dns.zones.first.rr_sets
=> [{"Name"=>"www", "Type"=>"A", "RData"=>"192.168.1.2"}]

Create zone

use dns.zones.create with :zone.

> zone = dns.zones.create(zone: 'sawanoboly4.net')

It creates new zone.

=>   <Fog::DNS::SakuraCloud::Zone
    id="112700799891",
    name="sawanoboly4.net",
    description=nil,
    status={"Zone"=>"sawanoboly4.net", "NS"=>["ns1.gslb2.sakura.ne.jp", "ns2.gslb2.sakura.ne.jp"]},
    settings={"DNS"=>{"ResourceRecordSets"=> nil}},
    tags=[]
  >

Delete zone

use dns.zones.delete('Zone_id')

> dns.zones.delete('112700797573')

=> true

or execute delete method for zone.

> dns.zones.first.delete

=> true

Modify ResourceRecordSets of Zone

First, load target zone.

> zone = dns.zones.get('112700797486')
=>   <Fog::DNS::SakuraCloud::Zone
    id="112700797486",
    name="sawanoboly.net",
    description=nil,
    rr_sets=[{"Name"=>"www", "Type"=>"A", "RData"=>"192.168.1.2"}, {"Name"=>"www", "Type"=>"A", "RData"=>"192.168.1.3"}, {"Name"=>"www", "Type"=>"A", "RData"=>"192.168.1.4"}],
    zone="sawanoboly.net",
    nameservers=["ns1.gslb2.sakura.ne.jp", "ns2.gslb2.sakura.ne.jp"],
    tags=[]
  >

create new rrset when empty, pass Array to #= method.

> zone.settings['DNS']['ResourceRecordSets'] = [{"Name"=>"www", "Type"=>"A", "RData"=>"192.168.1.2"}]
=> [{"Name"=>"www", "Type"=>"A", "RData"=>"192.168.1.2"}]

> zone.save
=> true

add record to rr_sets or delete from rr_sets. Then save it.

> zone.settings['DNS']['ResourceRecordSets'] <<  {"Name"=>"mail", "Type"=>"A", "RData"=>"192.168.1.5"}
=> [{"Name"=>"www", "Type"=>"A", "RData"=>"192.168.1.2"}, {"Name"=>"mail", "Type"=>"A", "RData"=>"192.168.1.5"}]

> zone.save

=> true
> zone.settings['DNS']['ResourceRecordSets'].delete({"Name"=>"www", "Type"=>"A", "RData"=>"192.168.1.2"})
=> {"Name"=>"www", "Type"=>"A", "RData"=>"192.168.1.2"}

> zone.save

=> true