mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[ibm] Initial IBM SmartCloud support
This commit is contained in:
parent
c8fbdbe16e
commit
65e572805e
48 changed files with 1353 additions and 0 deletions
|
@ -32,6 +32,9 @@ module Fog
|
|||
when :gogrid
|
||||
require 'fog/go_grid/compute'
|
||||
Fog::Compute::GoGrid.new(attributes)
|
||||
when :ibm
|
||||
require 'fog/ibm/compute'
|
||||
Fog::Compute::IBM.new(attributes)
|
||||
when :joyent
|
||||
require 'fog/joyent/compute'
|
||||
Fog::Compute::Joyent.new(attributes)
|
||||
|
|
|
@ -84,6 +84,8 @@ An alternate file may be used by placing its path in the FOG_RC environment vari
|
|||
:libvirt_password:
|
||||
:libvirt_uri:
|
||||
:libvirt_ip_command:
|
||||
:ibm_username:
|
||||
:ibm_password:
|
||||
#
|
||||
# End of Fog Credentials File
|
||||
#######################################################
|
||||
|
|
59
lib/fog/ibm.rb
Normal file
59
lib/fog/ibm.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
require(File.expand_path(File.join(File.dirname(__FILE__), 'core')))
|
||||
|
||||
module Fog
|
||||
module IBM
|
||||
|
||||
extend Fog::Provider
|
||||
|
||||
service(:compute, 'ibm/compute', 'Compute')
|
||||
service(:storage, 'ibm/storage', 'Storage')
|
||||
|
||||
class Connection < Fog::Connection
|
||||
|
||||
ENDPOINT = 'https://www-147.ibm.com/computecloud/enterprise/api/rest/20100331'
|
||||
|
||||
def initialize(user, password)
|
||||
require 'multi_json'
|
||||
@user = user
|
||||
@password = password
|
||||
@endpoint = URI.parse(ENDPOINT)
|
||||
@base_path = @endpoint.path
|
||||
super("#{@endpoint.scheme}://#{@endpoint.host}:#{@endpoint.port}")
|
||||
end
|
||||
|
||||
def request(options)
|
||||
options[:path] = @base_path + options[:path]
|
||||
options[:headers] ||= {}
|
||||
options[:headers]['Authorization'] = auth_header
|
||||
options[:headers]['Accept'] = 'application/json'
|
||||
options[:headers]['Accept-Encoding'] = 'gzip'
|
||||
response = super(options)
|
||||
|
||||
unless response.body.empty?
|
||||
response.body = MultiJson.decode(response.body)
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
def auth_header
|
||||
@auth_header ||= 'Basic ' + Base64.encode64("#{@user}:#{@password}").gsub("\n",'')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def self.form_body(params)
|
||||
{
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
:body => params.map {|pair| pair.map {|x| URI.escape(x) }.join('=') }.join('&')
|
||||
}
|
||||
end
|
||||
|
||||
def self.json_body(params)
|
||||
{
|
||||
:headers => { 'Content-Type' => 'application/json' },
|
||||
:body => MultiJson.encode(params)
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
87
lib/fog/ibm/compute.rb
Normal file
87
lib/fog/ibm/compute.rb
Normal file
|
@ -0,0 +1,87 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'ibm'))
|
||||
require 'fog/compute'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class IBM < Fog::Service
|
||||
|
||||
requires :ibm_user_id, :ibm_password
|
||||
recognizes :location
|
||||
|
||||
model_path 'fog/ibm/models/compute'
|
||||
|
||||
model :image
|
||||
collection :images
|
||||
model :server
|
||||
collection :servers
|
||||
model :address
|
||||
collection :addresses
|
||||
model :key
|
||||
collection :keys
|
||||
|
||||
request_path 'fog/ibm/requests/compute'
|
||||
|
||||
request :create_image
|
||||
request :clone_image
|
||||
request :delete_image
|
||||
request :get_images
|
||||
request :get_image
|
||||
request :get_image_agreement
|
||||
request :get_image_manifest
|
||||
# request :get_image_swbundles
|
||||
# request :get_image_swbundle
|
||||
|
||||
request :create_instance
|
||||
request :delete_instance
|
||||
request :modify_instance
|
||||
request :get_instances
|
||||
request :get_instance
|
||||
request :get_instance_logs
|
||||
# request :get_instance_swbundle
|
||||
|
||||
request :get_request
|
||||
|
||||
request :create_address
|
||||
request :delete_address
|
||||
request :get_addresses
|
||||
request :get_address_offerings
|
||||
request :get_vlans
|
||||
|
||||
request :create_key
|
||||
request :delete_key
|
||||
request :modify_key
|
||||
request :get_keys
|
||||
request :get_key
|
||||
|
||||
class Real
|
||||
def initialize(options={})
|
||||
@connection = Fog::IBM::Connection.new(options[:ibm_user_id], options[:ibm_password])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request(options)
|
||||
begin
|
||||
@connection.request(options)
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::Compute::IBM::NotFound.slurp(error)
|
||||
else
|
||||
error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def request(options)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
41
lib/fog/ibm/models/compute/address.rb
Normal file
41
lib/fog/ibm/models/compute/address.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Address < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :type
|
||||
attribute :location
|
||||
attribute :ip
|
||||
attribute :state
|
||||
attribute :instance_id, :aliases => 'instanceId'
|
||||
attribute :offering_id, :aliases => 'offeringId'
|
||||
attribute :vlan_id, :aliases => 'vlanId'
|
||||
attribute :hostname
|
||||
attribute :mode
|
||||
attribute :owner
|
||||
|
||||
def initialize(new_attributes={})
|
||||
super(new_attributes)
|
||||
self.offering_id ||= '20001223'
|
||||
self.location ||= '82'
|
||||
end
|
||||
|
||||
def save
|
||||
requires :offering_id, :location
|
||||
data = connection.create_address(location, offering_id)
|
||||
merge_attributes(data.body)
|
||||
true
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
connection.delete_address(id).body['success']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
lib/fog/ibm/models/compute/addresses.rb
Normal file
28
lib/fog/ibm/models/compute/addresses.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/ibm/models/compute/address'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
|
||||
class Addresses < Fog::Collection
|
||||
|
||||
model Fog::Compute::IBM::Address
|
||||
|
||||
def all
|
||||
load(connection.get_addresses.body['addresses'])
|
||||
end
|
||||
|
||||
def get(address_id)
|
||||
begin
|
||||
address = connection.get_addresses.body
|
||||
new(address['addresses'].find{|address| address['id'] == address_id.to_s })
|
||||
rescue Fog::Compute::IBM::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
34
lib/fog/ibm/models/compute/image.rb
Normal file
34
lib/fog/ibm/models/compute/image.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Image < Fog::Model
|
||||
identity :id
|
||||
attribute :architecture
|
||||
attribute :created_at, :aliases => 'createdTime'
|
||||
attribute :description
|
||||
attribute :documentation
|
||||
attribute :location
|
||||
attribute :manifest
|
||||
attribute :name
|
||||
attribute :owner
|
||||
attribute :platform
|
||||
attribute :product_codes, :aliases => 'productCodes'
|
||||
attribute :state
|
||||
attribute :supported_instance_types, :aliases => 'supportedInstanceTypes'
|
||||
attribute :visibility
|
||||
|
||||
attribute :volume_id
|
||||
|
||||
def save
|
||||
requires :id, :volume_id
|
||||
data = connection.create_image(id, volume_id)
|
||||
merge_attributes(data.body)
|
||||
data.body['success']
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/ibm/models/compute/images.rb
Normal file
27
lib/fog/ibm/models/compute/images.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/ibm/models/compute/image'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
|
||||
class Images < Fog::Collection
|
||||
|
||||
model Fog::Compute::IBM::Image
|
||||
|
||||
def all
|
||||
load(connection.get_images.body['images'])
|
||||
end
|
||||
|
||||
def get(image_id)
|
||||
begin
|
||||
new(connection.get_image(image_id).body)
|
||||
rescue Fog::Compute::IBM::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/ibm/models/compute/key.rb
Normal file
27
lib/fog/ibm/models/compute/key.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Key < Fog::Model
|
||||
identity :name, :aliases => 'keyName'
|
||||
attribute :default
|
||||
attribute :public_key, :aliases => 'keyMaterial'
|
||||
attribute :last_modified, :aliases => 'lastModifiedTime'
|
||||
|
||||
def save
|
||||
requires :name, :public_key
|
||||
data = connection.create_key(name, public_key)
|
||||
merge_attributes(data.body)
|
||||
data.body['success']
|
||||
end
|
||||
|
||||
def destroy
|
||||
data = connection.delete_key(identity)
|
||||
data.body['success']
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/ibm/models/compute/keys.rb
Normal file
27
lib/fog/ibm/models/compute/keys.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/ibm/models/compute/key'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
|
||||
class Keys < Fog::Collection
|
||||
|
||||
model Fog::Compute::IBM::Key
|
||||
|
||||
def all
|
||||
load(connection.get_keys.body['keys'])
|
||||
end
|
||||
|
||||
def get(key_id)
|
||||
begin
|
||||
new(connection.get_key(key_id).body)
|
||||
rescue Fog::Compute::IBM::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
84
lib/fog/ibm/models/compute/server.rb
Normal file
84
lib/fog/ibm/models/compute/server.rb
Normal file
|
@ -0,0 +1,84 @@
|
|||
require 'fog/compute/models/server'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
|
||||
class Server < Fog::Compute::Server
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :disk_size, :aliases => 'diskSize'
|
||||
attribute :expires_at, :aliases => 'expirationTime'
|
||||
attribute :image_id, :aliases => 'imageId'
|
||||
attribute :instance_type, :aliases => 'instanceType'
|
||||
attribute :ip
|
||||
attribute :key_name, :aliases => 'keyName'
|
||||
attribute :launched_at, :aliases => 'launchTime'
|
||||
attribute :location_id, :aliases => 'location'
|
||||
attribute :name
|
||||
attribute :owner
|
||||
attribute :primary_ip, :aliases => 'primaryIP'
|
||||
attribute :product_codes, :aliases => 'productCodes'
|
||||
attribute :request_id, :aliases => 'requestId'
|
||||
attribute :request_name, :aliases => 'requestName'
|
||||
attribute :root_only, :aliases => 'root-only'
|
||||
attribute :secondary_ip, :aliases => 'secondaryIP'
|
||||
attribute :software
|
||||
attribute :state, :aliases => 'status'
|
||||
attribute :volume_ids, :aliases => 'volumes'
|
||||
|
||||
def initialize(new_attributes={})
|
||||
super(new_attributes)
|
||||
self.name ||= 'fog-instance'
|
||||
self.image_id ||= '20025202'
|
||||
self.location_id ||= '82'
|
||||
self.instance_type ||= 'COP32.1/2048/60'
|
||||
self.key_name ||= 'fog'
|
||||
end
|
||||
|
||||
def save
|
||||
requires :name, :image_id, :instance_type, :location_id
|
||||
data = connection.create_instance(name, image_id, instance_type, location_id, key_name)
|
||||
data.body['instances'].each do |iattrs|
|
||||
if iattrs['name'] == name
|
||||
merge_attributes(iattrs)
|
||||
return true
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
def reboot
|
||||
requires :id
|
||||
connection.modify_instance(id, 'state' => 'restart')
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
data = connection.delete_instance(id)
|
||||
data.body['success']
|
||||
end
|
||||
|
||||
def attach(volume_id)
|
||||
requires :id
|
||||
data = connection.modify_instance(id, {'type' => 'attach', 'storageId' => volume_id})
|
||||
data.body
|
||||
end
|
||||
|
||||
def detach(volume_id)
|
||||
requires :id
|
||||
data = connection.modify_instance(id, {'type' => 'detach', 'storageId' => volume_id})
|
||||
data.body
|
||||
end
|
||||
|
||||
def ready?
|
||||
state == 5
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
27
lib/fog/ibm/models/compute/servers.rb
Normal file
27
lib/fog/ibm/models/compute/servers.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/ibm/models/compute/server'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
|
||||
class Servers < Fog::Collection
|
||||
|
||||
model Fog::Compute::IBM::Server
|
||||
|
||||
def all
|
||||
load(connection.get_instances.body['instances'])
|
||||
end
|
||||
|
||||
def get(server_id)
|
||||
begin
|
||||
new(connection.get_instance(server_id).body)
|
||||
rescue Fog::Compute::IBM::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
lib/fog/ibm/models/storage/offering.rb
Normal file
18
lib/fog/ibm/models/storage/offering.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class IBM
|
||||
class Offering < Fog::Model
|
||||
identity :id
|
||||
attribute :location
|
||||
attribute :name
|
||||
attribute :label
|
||||
attribute :capacity
|
||||
attribute :supported_sizes, :aliases => 'supportedSizes'
|
||||
attribute :supported_formats, :aliases => 'formats'
|
||||
attribute :price
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
lib/fog/ibm/models/storage/offerings.rb
Normal file
19
lib/fog/ibm/models/storage/offerings.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/ibm/models/storage/offering'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class IBM
|
||||
|
||||
class Offerings < Fog::Collection
|
||||
|
||||
model Fog::Storage::IBM::Offering
|
||||
|
||||
def all
|
||||
load(connection.get_offerings.body['volumes'])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
38
lib/fog/ibm/models/storage/volume.rb
Normal file
38
lib/fog/ibm/models/storage/volume.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class IBM
|
||||
class Volume < Fog::Model
|
||||
identity :id
|
||||
attribute :location
|
||||
attribute :instance_id, :aliases => 'instanceId'
|
||||
attribute :owner
|
||||
attribute :name
|
||||
attribute :format
|
||||
attribute :size
|
||||
attribute :state
|
||||
attribute :storage_area, :aliases => 'storageArea'
|
||||
attribute :created_at, :aliases => 'createdTime'
|
||||
attribute :product_codes, :aliases => 'productCodes'
|
||||
attribute :platform_version, :aliases => 'platformVersion'
|
||||
attribute :clone_status, :aliases => 'cloneStatus'
|
||||
|
||||
attribute :offering_id
|
||||
|
||||
def save
|
||||
requires :name, :offering_id, :format, :location, :size
|
||||
data = connection.create_volume(name, offering_id, format, location, size)
|
||||
merge_attributes(data.body)
|
||||
data.body['success']
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
connection.delete_volume(id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/ibm/models/storage/volumes.rb
Normal file
27
lib/fog/ibm/models/storage/volumes.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/ibm/models/storage/volume'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class IBM
|
||||
|
||||
class Volumes < Fog::Collection
|
||||
|
||||
model Fog::Storage::IBM::Volume
|
||||
|
||||
def all
|
||||
load(connection.get_volumes.body['volumes'])
|
||||
end
|
||||
|
||||
def get(volume_id)
|
||||
begin
|
||||
new(connection.get_volume(volume_id).body)
|
||||
rescue Fog::Storage::IBM::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
29
lib/fog/ibm/requests/compute/clone_image.rb
Normal file
29
lib/fog/ibm/requests/compute/clone_image.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Clone an image
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def clone_image(image_id, name, description, extra_params={})
|
||||
options = {
|
||||
:method => 'POST',
|
||||
:expects => 200,
|
||||
:path => "/offerings/image/#{image_id}"
|
||||
}
|
||||
params = {
|
||||
'name' => name,
|
||||
'description' => description
|
||||
}
|
||||
options.merge!(Fog::IBM.form_body(params.merge(extra_params)))
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/ibm/requests/compute/create_address.rb
Normal file
30
lib/fog/ibm/requests/compute/create_address.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Create an address
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def create_address(offering_id, location, vlan_id)
|
||||
options = {
|
||||
:method => 'POST',
|
||||
:expects => 200,
|
||||
:path => '/addresses',
|
||||
}
|
||||
params = {
|
||||
'offeringID' => offering_id,
|
||||
'location' => location,
|
||||
'vlanID' => vlan_id
|
||||
}
|
||||
options.merge!(Fog::IBM.form_body(params.merge(extra_params)))
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
29
lib/fog/ibm/requests/compute/create_image.rb
Normal file
29
lib/fog/ibm/requests/compute/create_image.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Create an image
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def create_image(instance_id, name, description, extra_params={})
|
||||
options = {
|
||||
:method => 'POST',
|
||||
:expects => 200,
|
||||
:path => "/instances/#{instance_id}",
|
||||
}
|
||||
params = {
|
||||
'name' => name,
|
||||
'description' => description
|
||||
}
|
||||
options.merge!(Fog::IBM.form_body(params.merge(extra_params)))
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
lib/fog/ibm/requests/compute/create_instance.rb
Normal file
31
lib/fog/ibm/requests/compute/create_instance.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Create an instance
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def create_instance(name, image_id, instance_type, location, extra_params={})
|
||||
options = {
|
||||
:method => 'POST',
|
||||
:expects => 200,
|
||||
:path => '/instances'
|
||||
}
|
||||
params = {
|
||||
'name' => name,
|
||||
'imageID' => image_id,
|
||||
'instanceType' => instance_type,
|
||||
'location' => location
|
||||
}
|
||||
options.merge!(Fog::IBM.form_body(params.merge(extra_params)))
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
29
lib/fog/ibm/requests/compute/create_key.rb
Normal file
29
lib/fog/ibm/requests/compute/create_key.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Create a key
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def create_key(name, public_key, extra_params={})
|
||||
options = {
|
||||
:method => 'POST',
|
||||
:expects => 200,
|
||||
:path => '/keys',
|
||||
}
|
||||
params = {
|
||||
'name' => name,
|
||||
'publicKey' => public_key
|
||||
}
|
||||
options.merge!(Fog::IBM.form_body(params.merge(extra_params)))
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ibm/requests/compute/delete_address.rb
Normal file
23
lib/fog/ibm/requests/compute/delete_address.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Delete an address
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def delete_address(address_id)
|
||||
request(
|
||||
:method => 'DELETE',
|
||||
:expects => 200,
|
||||
:path => "/addresses/#{address_id}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ibm/requests/compute/delete_image.rb
Normal file
23
lib/fog/ibm/requests/compute/delete_image.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Delete an image
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def delete_image(image_id)
|
||||
request(
|
||||
:method => 'DELETE',
|
||||
:expects => 200,
|
||||
:path => "/offerings/image/#{image_id}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ibm/requests/compute/delete_instance.rb
Normal file
23
lib/fog/ibm/requests/compute/delete_instance.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Terminate an instance
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def delete_instance(instance_id)
|
||||
request(
|
||||
:method => 'DELETE',
|
||||
:expects => 200,
|
||||
:path => "/instances/#{instance_id}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ibm/requests/compute/delete_key.rb
Normal file
23
lib/fog/ibm/requests/compute/delete_key.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Delete a key
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def delete_key(key_name)
|
||||
request(
|
||||
:method => 'DELETE',
|
||||
:expects => 200,
|
||||
:path => "/keys/#{key_name}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/ibm/requests/compute/get_address_offerings.rb
Normal file
26
lib/fog/ibm/requests/compute/get_address_offerings.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Returns address offerings
|
||||
#
|
||||
# ==== Parameters
|
||||
# No parameters
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# TODO: doc
|
||||
def get_address_offerings
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => '/offerings/address'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
lib/fog/ibm/requests/compute/get_addresses.rb
Normal file
24
lib/fog/ibm/requests/compute/get_addresses.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get addresses
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * instances<~Array>:
|
||||
# TODO: docs
|
||||
def get_addresses
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => '/addresses'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ibm/requests/compute/get_image.rb
Normal file
23
lib/fog/ibm/requests/compute/get_image.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get an image
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def get_image(image_id)
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => "/offerings/image/#{image_id}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ibm/requests/compute/get_image_agreement.rb
Normal file
23
lib/fog/ibm/requests/compute/get_image_agreement.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get an image
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def get_image_agreement(image_id)
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => "/offerings/image/#{image_id}/agreement"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ibm/requests/compute/get_image_manifest.rb
Normal file
23
lib/fog/ibm/requests/compute/get_image_manifest.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get an image manifest
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def get_image_manifest(image_id)
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => "/offerings/image/#{image_id}/manifest"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
lib/fog/ibm/requests/compute/get_images.rb
Normal file
24
lib/fog/ibm/requests/compute/get_images.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get available images
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * images<~Array>
|
||||
# TODO: docs
|
||||
def get_images
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => '/offerings/image'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ibm/requests/compute/get_instance.rb
Normal file
23
lib/fog/ibm/requests/compute/get_instance.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get an instance
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def get_instance(instance_id)
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => "/instances/#{instance_id}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/ibm/requests/compute/get_instance_logs.rb
Normal file
25
lib/fog/ibm/requests/compute/get_instance_logs.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get an instance's logs
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * logs<~Array>:
|
||||
# TODO: docs
|
||||
def get_instance_logs(instance_id, start_index=nil)
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => "/instances/#{instance_id}/logs" +
|
||||
(start_index ? "?startIndex=#{start_index}" : '')
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
35
lib/fog/ibm/requests/compute/get_instances.rb
Normal file
35
lib/fog/ibm/requests/compute/get_instances.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get instances
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * instances<~Array>:
|
||||
# TODO: docs
|
||||
def get_instances
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => '/instances'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def get_instances
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = { 'instances' => [] }
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ibm/requests/compute/get_key.rb
Normal file
23
lib/fog/ibm/requests/compute/get_key.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get a key
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def get_key(key_name)
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => "/keys/#{key_name}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
lib/fog/ibm/requests/compute/get_keys.rb
Normal file
24
lib/fog/ibm/requests/compute/get_keys.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get keys
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * images<~Array>
|
||||
# TODO: docs
|
||||
def get_keys
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => '/keys'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/ibm/requests/compute/get_request.rb
Normal file
27
lib/fog/ibm/requests/compute/get_request.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get list of instances for a request
|
||||
#
|
||||
# ==== Parameters
|
||||
# * request_id<~String> - Id of request
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# TODO: doc
|
||||
def get_request(request_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "computecloud/enterprise/api/rest/20100331/requests/#{request_id}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
24
lib/fog/ibm/requests/compute/get_vlans.rb
Normal file
24
lib/fog/ibm/requests/compute/get_vlans.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get vlans
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * images<~Array>
|
||||
# TODO: docs
|
||||
def get_vlans
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => '/offerings/vlan'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/ibm/requests/compute/modify_instance.rb
Normal file
25
lib/fog/ibm/requests/compute/modify_instance.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Modify an instance
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def modify_instance(instance_id, params={})
|
||||
options = {
|
||||
:method => 'PUT',
|
||||
:expects => 200,
|
||||
:path => "/instances/#{instance_id}",
|
||||
}
|
||||
options.merge!(Fog::IBM.form_body(params))
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/ibm/requests/compute/modify_key.rb
Normal file
25
lib/fog/ibm/requests/compute/modify_key.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Modify a key
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def modify_key(key_name, params={})
|
||||
options = {
|
||||
:method => 'PUT',
|
||||
:expects => 200,
|
||||
:path => "/keys/#{key_name}",
|
||||
}
|
||||
options.merge!(Fog::IBM.form_body(params))
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/ibm/requests/storage/create_volume.rb
Normal file
32
lib/fog/ibm/requests/storage/create_volume.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Create a volume
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def create_volume(name, offering_id, format, location, size, extra_params={})
|
||||
options = {
|
||||
:method => 'POST',
|
||||
:expects => 200,
|
||||
:path => '/storage',
|
||||
}
|
||||
params = {
|
||||
'name' => name,
|
||||
'offeringID' => offering_id,
|
||||
'format' => format,
|
||||
'location' => location,
|
||||
'size' => size
|
||||
}
|
||||
options.merge!(form_body(params.merge(extra_params)))
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ibm/requests/storage/delete_volume.rb
Normal file
23
lib/fog/ibm/requests/storage/delete_volume.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Delete a volume
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def delete_volume(volume_id)
|
||||
request(
|
||||
:method => 'DELETE',
|
||||
:expects => 200,
|
||||
:path => "/storage/#{volume_id}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/ibm/requests/storage/get_offerings.rb
Normal file
25
lib/fog/ibm/requests/storage/get_offerings.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get available storage offerings
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * volumes<~Array>
|
||||
# TODO: docs
|
||||
def get_offerings
|
||||
options = {
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => '/offerings/storage'
|
||||
}
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ibm/requests/storage/get_volume.rb
Normal file
23
lib/fog/ibm/requests/storage/get_volume.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get a volume
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# TODO: docs
|
||||
def get_volume(volume_id)
|
||||
request(
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => "/storage/#{volume_id}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/ibm/requests/storage/get_volumes.rb
Normal file
25
lib/fog/ibm/requests/storage/get_volumes.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class IBM
|
||||
class Real
|
||||
|
||||
# Get existing volumes
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * volumes<~Array>
|
||||
# TODO: docs
|
||||
def get_volumes
|
||||
options = {
|
||||
:method => 'GET',
|
||||
:expects => 200,
|
||||
:path => '/storage'
|
||||
}
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
59
lib/fog/ibm/storage.rb
Normal file
59
lib/fog/ibm/storage.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'ibm'))
|
||||
require 'fog/storage'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class IBM < Fog::Service
|
||||
|
||||
requires :ibm_user_id, :ibm_password
|
||||
recognizes :location
|
||||
|
||||
model_path 'fog/ibm/models/storage'
|
||||
|
||||
model :offering
|
||||
collection :offerings
|
||||
model :volume
|
||||
collection :volumes
|
||||
|
||||
request_path 'fog/ibm/requests/storage'
|
||||
|
||||
request :get_offerings
|
||||
|
||||
request :create_volume
|
||||
request :delete_volume
|
||||
request :get_volumes
|
||||
request :get_volume
|
||||
|
||||
class Real
|
||||
def initialize(options={})
|
||||
@connection = Fog::IBM::Connection.new(options[:ibm_user_id], options[:ibm_password])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request(options)
|
||||
begin
|
||||
@connection.request(options)
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::Storage::IBM::NotFound.slurp(error)
|
||||
else
|
||||
error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def request(options)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,6 +10,7 @@ require 'fog/ecloud'
|
|||
require 'fog/glesys'
|
||||
require 'fog/go_grid'
|
||||
require 'fog/google'
|
||||
require 'fog/ibm'
|
||||
require 'fog/joyent'
|
||||
require 'fog/libvirt'
|
||||
require 'fog/linode'
|
||||
|
|
|
@ -14,6 +14,9 @@ module Fog
|
|||
when :google
|
||||
require 'fog/google/storage'
|
||||
Fog::Storage::Google.new(attributes)
|
||||
when :ibm
|
||||
require 'fog/ibm/storage'
|
||||
Fog::Storage::IBM.new(attributes)
|
||||
when :local
|
||||
require 'fog/local/storage'
|
||||
Fog::Storage::Local.new(attributes)
|
||||
|
|
Loading…
Reference in a new issue