mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
create/delete slices for slicehost
This commit is contained in:
parent
ca413e9d84
commit
4099ba9310
12 changed files with 203 additions and 14 deletions
|
@ -11,11 +11,14 @@ module Fog
|
|||
end
|
||||
|
||||
def self.reload
|
||||
load "fog/slicehost/parsers/create_slice.rb"
|
||||
load "fog/slicehost/parsers/get_backups.rb"
|
||||
load "fog/slicehost/parsers/get_flavors.rb"
|
||||
load "fog/slicehost/parsers/get_images.rb"
|
||||
load "fog/slicehost/parsers/get_slices.rb"
|
||||
|
||||
load "fog/slicehost/requests/create_slice.rb"
|
||||
load "fog/slicehost/requests/delete_slice.rb"
|
||||
load "fog/slicehost/requests/get_backups.rb"
|
||||
load "fog/slicehost/requests/get_flavors.rb"
|
||||
load "fog/slicehost/requests/get_images.rb"
|
||||
|
@ -35,10 +38,20 @@ module Fog
|
|||
end
|
||||
|
||||
def request(params)
|
||||
headers = {
|
||||
'Authorization' => "Basic #{Base64.encode64(@password).gsub("\n",'')}"
|
||||
}
|
||||
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 => { 'Authorization' => "Basic #{Base64.encode64(@password).gsub("\n",'')}"},
|
||||
:headers => headers,
|
||||
:host => @host,
|
||||
:method => params[:method],
|
||||
:parser => params[:parser],
|
||||
|
|
29
lib/fog/slicehost/parsers/create_slice.rb
Normal file
29
lib/fog/slicehost/parsers/create_slice.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Slicehost
|
||||
|
||||
class CreateSlice < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'address'
|
||||
@response['addresses'] ||= []
|
||||
@response['addresses'] << @value
|
||||
when 'backup-id', 'flavor-id', 'id', 'image-id', 'progress'
|
||||
@response[name] = @value.to_i
|
||||
when 'bw-in', 'bw-out'
|
||||
@response[name] = @value.to_f
|
||||
when 'name', 'root-password', 'status'
|
||||
@response[name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -16,7 +16,7 @@ module Fog
|
|||
@backup = {}
|
||||
when 'date'
|
||||
@backup[name] = Time.parse(@value)
|
||||
when 'id', 'slice_id'
|
||||
when 'id', 'slice-id'
|
||||
@backup[name] = @value.to_i
|
||||
when 'name'
|
||||
@backup[name] = @value
|
||||
|
|
|
@ -14,8 +14,10 @@ module Fog
|
|||
when 'address'
|
||||
@slice['addresses'] ||= []
|
||||
@slice['addresses'] << @value
|
||||
when 'backup_id', 'bw_in', 'bw_out', 'flavor_id', 'id', 'image_id', 'progress'
|
||||
when 'backup-id', 'flavor-id', 'id', 'image-id', 'progress'
|
||||
@slice[name] = @value.to_i
|
||||
when 'bw-in', 'bw-out'
|
||||
@slice[name] = @value.to_f
|
||||
when 'name', 'status'
|
||||
@slice[name] = @value
|
||||
when 'slice'
|
||||
|
|
50
lib/fog/slicehost/requests/create_slice.rb
Normal file
50
lib/fog/slicehost/requests/create_slice.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
class Slicehost
|
||||
|
||||
# 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
|
||||
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
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
class Slicehost
|
||||
|
||||
def get_slices
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
48
lib/fog/slicehost/requests/delete_slice.rb
Normal file
48
lib/fog/slicehost/requests/delete_slice.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
class Slicehost
|
||||
|
||||
# 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
|
||||
def delete_slice(slice_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'DELETE',
|
||||
:path => "slices/#{slice_id}.xml"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
class Slicehost
|
||||
|
||||
def get_slices
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -11,7 +11,7 @@ unless Fog.mocking?
|
|||
# * '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
|
||||
# * 'slice-id'<~Integer> - Id of slice the backup was made from
|
||||
def get_backups
|
||||
request(
|
||||
:expects => 200,
|
||||
|
|
|
@ -9,12 +9,12 @@ unless Fog.mocking?
|
|||
# * 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
|
||||
# * '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
|
||||
# * '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
|
||||
|
|
29
spec/slicehost/requests/create_slice_spec.rb
Normal file
29
spec/slicehost/requests/create_slice_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
|
||||
describe 'Slicehost.create_slice' do
|
||||
describe 'success' do
|
||||
|
||||
after(:each) do
|
||||
eventually(128) do
|
||||
slicehost.delete_slice(@slice_id)
|
||||
end
|
||||
end
|
||||
|
||||
it "should return proper attributes" do
|
||||
# flavor_id 1: 256 ram, image_id 3: Gentoo 2008.0
|
||||
actual = slicehost.create_slice(1, 3, 'fogslice').body
|
||||
actual['addresses'].should be_a(Array)
|
||||
# actual['backup-id'].should be_an(Integer)
|
||||
actual['bw-in'].should be_an(Float)
|
||||
actual['bw-out'].should be_an(Float)
|
||||
actual['flavor-id'].should be_an(Integer)
|
||||
actual['id'].should be_an(Integer)
|
||||
actual['image-id'].should be_an(Integer)
|
||||
actual['name'].should be_an(String)
|
||||
actual['progress'].should be_an(Integer)
|
||||
actual['root-password'].should be_a(String)
|
||||
actual['status'].should be_an(String)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
18
spec/slicehost/requests/delete_slice_spec.rb
Normal file
18
spec/slicehost/requests/delete_slice_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
|
||||
describe 'Slicehost.delete_slice' do
|
||||
describe 'success' do
|
||||
|
||||
before(:each) do
|
||||
# flavor_id 1: 256 ram, image_id 3: Gentoo 2008.0
|
||||
@slice_id = slicehost.create_slice(1, 3, 'fog_slice').body['id']
|
||||
end
|
||||
|
||||
it "should return proper attributes" do
|
||||
eventually(128) do
|
||||
actual = slicehost.delete_slice(@slice_id)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@ describe 'Slicehost.get_backups' do
|
|||
# backup['date'].should be_a(String)
|
||||
# backup['id'].should be_an(Integer)
|
||||
# backup['name'].should be_an(String)
|
||||
# backup['slice_id'].should be_an(Integer)
|
||||
# backup['slice-id'].should be_an(Integer)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,12 +8,12 @@ describe 'Slicehost.get_slices' do
|
|||
actual['slices'].should be_an(Array)
|
||||
slice = actual['slices'].first
|
||||
# slice['addresses'].should be_a(Array)
|
||||
# slice['backup_id'].should be_an(Integer)
|
||||
# slice['bw_in'].should be_an(Integer)
|
||||
# slice['bw_out'].should be_an(Integer)
|
||||
# slice['flavor_id'].should be_an(Integer)
|
||||
# slice['backup-id'].should be_an(Integer)
|
||||
# slice['bw-in'].should be_an(Integer)
|
||||
# slice['bw-out'].should be_an(Integer)
|
||||
# slice['flavor-id'].should be_an(Integer)
|
||||
# slice['id'].should be_an(Integer)
|
||||
# slice['image_id'].should be_an(Integer)
|
||||
# slice['image-id'].should be_an(Integer)
|
||||
# slice['name'].should be_an(String)
|
||||
# slice['progress'].should be_an(Integer)
|
||||
# slice['status'].should be_an(String)
|
||||
|
|
Loading…
Add table
Reference in a new issue