Class: Fog::Slicehost

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/slicehost.rb,
lib/fog/slicehost/models/image.rb,
lib/fog/slicehost/models/flavor.rb,
lib/fog/slicehost/models/images.rb,
lib/fog/slicehost/models/server.rb,
lib/fog/slicehost/models/flavors.rb,
lib/fog/slicehost/models/servers.rb,
lib/fog/slicehost/requests/get_image.rb,
lib/fog/slicehost/requests/get_image.rb,
lib/fog/slicehost/requests/get_slice.rb,
lib/fog/slicehost/requests/get_slice.rb,
lib/fog/slicehost/requests/get_flavor.rb,
lib/fog/slicehost/requests/get_flavor.rb,
lib/fog/slicehost/requests/get_images.rb,
lib/fog/slicehost/requests/get_images.rb,
lib/fog/slicehost/requests/get_slices.rb,
lib/fog/slicehost/requests/get_slices.rb,
lib/fog/slicehost/requests/get_backups.rb,
lib/fog/slicehost/requests/get_backups.rb,
lib/fog/slicehost/requests/get_flavors.rb,
lib/fog/slicehost/requests/get_flavors.rb,
lib/fog/slicehost/requests/create_slice.rb,
lib/fog/slicehost/requests/create_slice.rb,
lib/fog/slicehost/requests/delete_slice.rb,
lib/fog/slicehost/requests/delete_slice.rb,
lib/fog/slicehost/requests/reboot_slice.rb,
lib/fog/slicehost/requests/reboot_slice.rb

Defined Under Namespace

Classes: Flavor, Flavors, Image, Images, Server, Servers

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Slicehost

Returns a new instance of Slicehost.



49
50
51
52
53
54
55
56
# File 'lib/fog/slicehost.rb', line 49

def initialize(options={})
  unless @slicehost_password = options[:slicehost_password]
    raise ArgumentError.new('slicehost_password is required to access slicehost')
  end
  @host       = options[:host]      || "api.slicehost.com"
  @port       = options[:port]      || 443
  @scheme     = options[:scheme]    || 'https'
end

Class Method Details

.dataObject



5
6
7
# File 'lib/fog/slicehost.rb', line 5

def self.data
  @data
end

.dependenciesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/slicehost.rb', line 13

def self.dependencies
  [
    "fog/slicehost/models/flavor.rb",
    "fog/slicehost/models/flavors.rb",
    "fog/slicehost/models/image.rb",
    "fog/slicehost/models/images.rb",
    "fog/slicehost/models/server.rb",
    "fog/slicehost/models/servers.rb",
    "fog/slicehost/parsers/create_slice.rb",
    "fog/slicehost/parsers/get_backups.rb",
    "fog/slicehost/parsers/get_flavor.rb",
    "fog/slicehost/parsers/get_flavors.rb",
    "fog/slicehost/parsers/get_image.rb",
    "fog/slicehost/parsers/get_images.rb",
    "fog/slicehost/parsers/get_slice.rb",
    "fog/slicehost/parsers/get_slices.rb",
    "fog/slicehost/requests/create_slice.rb",
    "fog/slicehost/requests/delete_slice.rb",
    "fog/slicehost/requests/get_backups.rb",
    "fog/slicehost/requests/get_flavor.rb",
    "fog/slicehost/requests/get_flavors.rb",
    "fog/slicehost/requests/get_image.rb",
    "fog/slicehost/requests/get_images.rb",
    "fog/slicehost/requests/get_slice.rb",
    "fog/slicehost/requests/get_slices.rb",
    "fog/slicehost/requests/reboot_slice.rb"
  ]
end

.reloadObject



42
43
44
45
46
47
# File 'lib/fog/slicehost.rb', line 42

def self.reload
  self.dependencies.each {|dependency| load(dependency)}
  if Fog.mocking?
    reset_data
  end
end

.reset_dataObject



8
9
10
# File 'lib/fog/slicehost.rb', line 8

def self.reset_data
  @data = {}
end

Instance Method Details

#create_slice(flavor_id, image_id, name) ⇒ Object

Get list of slices

Parameters

  • flavor_id<~Integer> - Id of flavor to create slice with

  • image_id<~Integer> - Id of image to create slice with

  • name<~String> - Name of slice

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘addresses’<~Array> - Ip addresses for the slice

      • ‘backup-id’<~Integer> - Id of backup slice was booted from

      • ‘bw-in’<~Integer> - Incoming bandwidth total for current billing cycle, in Gigabytes

      • ‘bw-out’<~Integer> - Outgoing bandwidth total for current billing cycle, in Gigabytes

      • ‘flavor-id’<~Integer> - Id of flavor slice was booted from

      • ‘id’<~Integer> - Id of the slice

      • ‘image-id’<~Integer> - Id of image slice was booted from

      • ‘name’<~String> - Name of the slice

      • ‘progress’<~Integer> - Progress of current action, in percentage

      • ‘root-password’<~String> - Root password of slice

      • ‘status’<~String> - Current status of the slice

Raises:



26
27
28
29
30
31
32
33
34
# File 'lib/fog/slicehost/requests/create_slice.rb', line 26

def create_slice(flavor_id, image_id, name)
  request(
    :body     => %Q{<?xml version="1.0" encoding="UTF-8"?><slice><flavor-id type="integer">#{flavor_id}</flavor-id><image-id type="integer">#{image_id}</image-id><name>#{name}</name></slice>},
    :expects  => 201,
    :method   => 'POST',
    :parser   => Fog::Parsers::Slicehost::CreateSlice.new,
    :path     => 'slices.xml'
  )
end

#delete_slice(slice_id) ⇒ Object

Get list of slices

Parameters

  • flavor_id<~Integer> - Id of flavor to create slice with

  • image_id<~Integer> - Id of image to create slice with

  • name<~String> - Name of slice

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘addresses’<~Array> - Ip addresses for the slice

      • ‘backup-id’<~Integer> - Id of backup slice was booted from

      • ‘bw-in’<~Integer> - Incoming bandwidth total for current billing cycle, in Gigabytes

      • ‘bw-out’<~Integer> - Outgoing bandwidth total for current billing cycle, in Gigabytes

      • ‘flavor-id’<~Integer> - Id of flavor slice was booted from

      • ‘id’<~Integer> - Id of the slice

      • ‘image-id’<~Integer> - Id of image slice was booted from

      • ‘name’<~String> - Name of the slice

      • ‘progress’<~Integer> - Progress of current action, in percentage

      • ‘root-password’<~String> - Root password of slice

      • ‘status’<~String> - Current status of the slice

Raises:



26
27
28
29
30
31
32
# File 'lib/fog/slicehost/requests/delete_slice.rb', line 26

def delete_slice(slice_id)
  request(
    :expects  => 200,
    :method   => 'DELETE',
    :path     => "slices/#{slice_id}.xml"
  )
end

#flavorsObject



4
5
6
# File 'lib/fog/slicehost/models/flavors.rb', line 4

def flavors
  Fog::Slicehost::Flavors.new(:connection => self)
end

#get_backupsObject

Get list of backups

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘date’<~Time> - Timestamp of backup creation

      • ‘id’<~Integer> - Id of the backup

      • ‘name’<~String> - Name of the backup

      • ‘slice-id’<~Integer> - Id of slice the backup was made from

Raises:



15
16
17
18
19
20
21
22
# File 'lib/fog/slicehost/requests/get_backups.rb', line 15

def get_backups
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Slicehost::GetBackups.new,
    :path     => 'backups.xml'
  )
end

#get_flavor(flavor_id) ⇒ Object

Get details of a flavor

Parameters

  • flavor_id<~Integer> - Id of flavor to lookup

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘id’<~Integer> - Id of the flavor

      • ‘name’<~String> - Name of the flavor

      • ‘price’<~Integer> - Price in cents

      • ‘ram’<~Integer> - Amount of ram for the flavor

Raises:



18
19
20
21
22
23
24
25
# File 'lib/fog/slicehost/requests/get_flavor.rb', line 18

def get_flavor(flavor_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Slicehost::GetFlavor.new,
    :path     => "flavors/#{flavor_id}.xml"
  )
end

#get_flavorsObject

Get list of flavors

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘id’<~Integer> - Id of the flavor

      • ‘name’<~String> - Name of the flavor

      • ‘price’<~Integer> - Price in cents

      • ‘ram’<~Integer> - Amount of ram for the flavor

Raises:



15
16
17
18
19
20
21
22
# File 'lib/fog/slicehost/requests/get_flavors.rb', line 15

def get_flavors
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Slicehost::GetFlavors.new,
    :path     => 'flavors.xml'
  )
end

#get_image(image_id) ⇒ Object

Get details of an image

Parameters

  • image_id<~Integer> - Id of image to lookup

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘id’<~Integer> - Id of the image

      • ‘name’<~String> - Name of the image

Raises:



16
17
18
19
20
21
22
23
# File 'lib/fog/slicehost/requests/get_image.rb', line 16

def get_image(image_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Slicehost::GetImage.new,
    :path     => "images/#{image_id}.xml"
  )
end

#get_imagesObject

Get list of images

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘id’<~Integer> - Id of the image

      • ‘name’<~String> - Name of the image

Raises:



13
14
15
16
17
18
19
20
# File 'lib/fog/slicehost/requests/get_images.rb', line 13

def get_images
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Slicehost::GetImages.new,
    :path     => 'images.xml'
  )
end

#get_slice(id) ⇒ Object

Get details of a slice

Parameters

  • slice_id<~Integer> - Id of slice to lookup

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘addresses’<~Array> - Ip addresses for the slice

      • ‘backup-id’<~Integer> - Id of backup slice was booted from

      • ‘bw-in’<~Float> - Incoming bandwidth total for current billing cycle, in Gigabytes

      • ‘bw-out’<~Float> - Outgoing bandwidth total for current billing cycle, in Gigabytes

      • ‘flavor_id’<~Integer> - Id of flavor slice was booted from

      • ‘id’<~Integer> - Id of the slice

      • ‘image-id’<~Integer> - Id of image slice was booted from

      • ‘name’<~String> - Name of the slice

      • ‘progress’<~Integer> - Progress of current action, in percentage

      • ‘status’<~String> - Current status of the slice

Raises:



24
25
26
27
28
29
30
31
# File 'lib/fog/slicehost/requests/get_slice.rb', line 24

def get_slice(slice_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Slicehost::GetSlice.new,
    :path     => "/slices/#{slice_id}.xml"
  )
end

#get_slicesObject

Get list of slices

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘addresses’<~Array> - Ip addresses for the slice

      • ‘backup-id’<~Integer> - Id of backup slice was booted from

      • ‘bw-in’<~Float> - Incoming bandwidth total for current billing cycle, in Gigabytes

      • ‘bw-out’<~Float> - Outgoing bandwidth total for current billing cycle, in Gigabytes

      • ‘flavor_id’<~Integer> - Id of flavor slice was booted from

      • ‘id’<~Integer> - Id of the slice

      • ‘image-id’<~Integer> - Id of image slice was booted from

      • ‘name’<~String> - Name of the slice

      • ‘progress’<~Integer> - Progress of current action, in percentage

      • ‘status’<~String> - Current status of the slice

Raises:



21
22
23
24
25
26
27
28
# File 'lib/fog/slicehost/requests/get_slices.rb', line 21

def get_slices
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Slicehost::GetSlices.new,
    :path     => 'slices.xml'
  )
end

#images(attributes = {}) ⇒ Object



4
5
6
7
8
# File 'lib/fog/slicehost/models/images.rb', line 4

def images(attributes = {})
  Fog::Slicehost::Images.new({
    :connection => self
  }.merge!(attributes))
end

#reboot_slice(slice_id, type = 'SOFT') ⇒ Object

Reboot slice

Parameters

  • slice_id<~Integer> - Id of server to reboot

  • type<~String> - Type of reboot, must be in [‘HARD’, ‘SOFT’]

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘addresses’<~Array> - Ip addresses for the slice

      • ‘backup-id’<~Integer> - Id of backup slice was booted from

      • ‘bw-in’<~Float> - Incoming bandwidth total for current billing cycle, in Gigabytes

      • ‘bw-out’<~Float> - Outgoing bandwidth total for current billing cycle, in Gigabytes

      • ‘flavor_id’<~Integer> - Id of flavor slice was booted from

      • ‘id’<~Integer> - Id of the slice

      • ‘image-id’<~Integer> - Id of image slice was booted from

      • ‘name’<~String> - Name of the slice

      • ‘progress’<~Integer> - Progress of current action, in percentage

      • ‘status’<~String> - Current status of the slice



24
25
26
27
28
29
30
31
32
# File 'lib/fog/slicehost/requests/reboot_slice.rb', line 24

def reboot_slice(slice_id, type = 'SOFT')
  request(
    :body     => '', # Gives a 411 Length Required without this
    :expects  => 200,
    :method   => 'PUT',
    :parser   => Fog::Parsers::Slicehost::GetSlice.new,
    :path     => "/slices/#{slice_id}/#{'hard_' if type == 'HARD'}reboot.xml"
  )
end

#request(params) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fog/slicehost.rb', line 58

def request(params)
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
  headers = {
    'Authorization' => "Basic #{Base64.encode64(@slicehost_password).chomp!}"
  }
  case params[:method]
  when 'DELETE', 'GET', 'HEAD'
    headers['Accept'] = 'application/xml'
  when 'POST', 'PUT'
    headers['Content-Type'] = 'application/xml'
  end

  response = @connection.request({
    :body     => params[:body],
    :expects  => params[:expects],
    :headers  => headers.merge!(params[:headers] || {}),
    :host     => @host,
    :method   => params[:method],
    :parser   => params[:parser],
    :path     => params[:path]
  })

  response
end

#serversObject



4
5
6
# File 'lib/fog/slicehost/models/servers.rb', line 4

def servers
  Fog::Slicehost::Servers.new(:connection => self)
end