[ninefold|compute] Ninefold List Functionality.

This commit is contained in:
Lincoln Stoll 2011-05-05 15:59:50 -07:00
parent a2de6b6065
commit 81ae21b0c8
15 changed files with 496 additions and 48 deletions

View File

@ -25,53 +25,15 @@ module Fog
#model :user
request_path 'fog/compute/requests/ninefold'
request :deploy_virtual_machine
#request :activate_console_server
#request :add_listeners_load_balancer
#request :add_nodes_load_balancer
#request :create_api_client
#request :create_cloud_ip
#request :create_image
#request :create_load_balancer
#request :destroy_api_client
#request :destroy_cloud_ip
#request :destroy_image
#request :destroy_load_balancer
#request :destroy_server
#request :get_account
#request :get_api_client
#request :get_cloud_ip
#request :get_image
#request :get_interface
#request :get_load_balancer
#request :get_server
#request :get_server_type
#request :get_user
#request :get_zone
#request :list_api_clients
#request :list_cloud_ips
#request :list_images
#request :list_load_balancers
#request :list_server_types
#request :list_servers
#request :list_users
#request :list_zones
#request :map_cloud_ip
#request :remove_listeners_load_balancer
#request :remove_nodes_load_balancer
#request :reset_ftp_password_account
#request :resize_server
#request :shutdown_server
#request :snapshot_server
#request :start_server
#request :stop_server
#request :unmap_cloud_ip
#request :update_account
#request :update_api_client
#request :update_image
#request :update_load_balancer
#request :update_server
#request :update_user
request :list_accounts
request :list_events
request :list_service_offerings
request :list_disk_offerings
request :list_capabilities
request :list_hypervisors
request :list_zones
request :list_network_offerings
request :list_resource_limits
class Mock
@ -126,7 +88,25 @@ module Fog
response = @connection.request(options)
end
unless response.body.empty?
# Because the response is some weird xml-json thing, we need to try and mung
# the values out with a prefix, and if there is an empty data entry return an
# empty version of the expected type (if provided)
response = JSON.parse(response.body)
if options.has_key? :response_prefix
keys = options[:response_prefix].split('/')
keys.each do |k|
if response[k]
response = response[k]
elsif options[:response_type]
response = options[:response_type]
break
else
end
end
response
else
response
end
end
end
@ -138,7 +118,6 @@ module Fog
end
def encode_signature(data)
p @ninefold_compute_secret
Base64.encode64(OpenSSL::HMAC.digest('sha1', @ninefold_compute_secret, URI.encode(data.downcase).gsub('+', '%20'))).chomp
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_accounts(options = {})
request('listAccounts', options, :expects => [200],
:response_prefix => 'listaccountsresponse/account', :response_type => Array)
end
end
class Mock
def list_accounts(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_capabilities(options = {})
request('listCapabilities', options, :expects => [200],
:response_prefix => 'listcapabilitiesresponse/capability', :response_type => Array)
end
end
class Mock
def list_capabilities(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_disk_offerings(options = {})
request('listDiskOfferings', options, :expects => [200],
:response_prefix => 'listdiskofferingsresponse/diskoffering', :response_type => Array)
end
end
class Mock
def list_disk_offerings(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_events(options = {})
request('listEvents', options, :expects => [200],
:response_prefix => 'listeventsresponse/event', :response_type => Array)
end
end
class Mock
def list_events(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_hypervisors(options = {})
request('listHypervisors', options, :expects => [200],
:response_prefix => 'listhypervisorsresponse/hypervisor', :response_type => Array)
end
end
class Mock
def list_hypervisors(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_network_offerings(options = {})
request('listNetworkOfferings', options, :expects => [200],
:response_prefix => 'listnetworkofferingsresponse/networkoffering', :response_type => Array)
end
end
class Mock
def list_network_offerings(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_public_ip_addresses(options = {})
request('listPublicIpAddresses', options, :expects => [200],
:response_prefix => 'listpublicipaddressesresponse/publicipaddress', :response_type => Array)
end
end
class Mock
def list_public_ip_addresses(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_resource_limits(options = {})
request('listResourceLimits', options, :expects => [200],
:response_prefix => 'listresourcelimitsresponse/resourcelimit', :response_type => Array)
end
end
class Mock
def list_resource_limits(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_service_offerings(options = {})
request('listServiceOfferings', options, :expects => [200],
:response_prefix => 'listserviceofferingsresponse/serviceoffering', :response_type => Array)
end
end
class Mock
def list_service_offerings(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_templates(options = {})
request('listTemplates', options, :expects => [200],
:response_prefix => 'listtemplatesresponse/template', :response_type => Array)
end
end
class Mock
def list_templates(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_virtual_machines(options = {})
request('listVirtualMachines', options, :expects => [200],
:response_prefix => 'listvirtualmachinesresponse/virtualmachine')
end
end
class Mock
def list_virtual_machines(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_zones(options = {})
request('listZones', options, :expects => [200],
:response_prefix => 'listzonesresponse/zone', :response_type => Array)
end
end
class Mock
def list_zones(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View File

@ -0,0 +1,137 @@
class Ninefold
module Compute
module TestSupport
# image img-9vxqi = Ubuntu Maverick 10.10 server
IMAGE_IDENTIFER = "img-9vxqi"
end
module Formats
module Lists
SERVICE_OFFERING = {
"id" => Integer,
"name" => String,
"displaytext" => String,
"cpunumber" => Integer,
"cpuspeed" => Integer,
"memory" => Integer,
"created" => String,
"storagetype" => String,
"offerha" => Fog::Boolean,
"domainid" => Integer,
"domain" => String
}
#SERVICE_OFFERINGS = [Ninefold::Compute::Formats::Lists::SERVICE_OFFERING]
ACCOUNTS = [{
"id"=>Integer,
"name"=>String,
"accounttype"=>Integer,
"domainid"=>Integer,
"domain"=>String,
"receivedbytes"=>Integer,
"sentbytes"=>Integer,
"vmlimit"=>String,
"vmtotal"=>Integer,
"vmavailable"=>String,
"iplimit"=>String,
"iptotal"=>Integer,
"ipavailable"=>String,
"volumelimit"=>String,
"volumetotal"=>Integer,
"volumeavailable"=>String,
"snapshotlimit"=>String,
"snapshottotal"=>Integer,
"snapshotavailable"=>String,
"templatelimit"=>String,
"templatetotal"=>Integer,
"templateavailable"=>String,
"vmstopped"=>Integer,
"vmrunning"=>Integer,
"state"=>String,
"user"=> [{
"id"=>Integer,
"username"=>String,
"firstname"=>String,
"lastname"=>String,
"email"=>String,
"created"=>String,
"state"=>String,
"account"=>String,
"accounttype"=>Integer,
"domainid"=>Integer,
"domain"=>String,
"apikey"=>String,
"secretkey"=>String
}]
}]
EVENTS = [{
"id"=>Integer,
"username"=>String,
"type"=>String,
"level"=>String,
"description"=>String,
"account"=>String,
"domainid"=>Integer,
"domain"=>String,
"created"=>String,
"state"=>String,
"parentid"=>Integer
}]
SERVICE_OFFERINGS = [{
"id"=>Integer,
"name"=>String,
"displaytext"=>String,
"cpunumber"=>Integer,
"cpuspeed"=>Integer,
"memory"=>Integer,
"created"=>String,
"storagetype"=>String,
"offerha"=>Fog::Boolean,
"domainid"=>Integer,
"domain"=>String
}]
DISK_OFFERINGS = [{
"id"=>Integer,
"domainid"=>Integer,
"domain"=>String,
"name"=>String,
"displaytext"=>String,
"disksize"=>Integer,
"created"=>String,
"iscustomized"=>Fog::Boolean,
"tags"=>String
}]
CAPABILITIES = {
"securitygroupsenabled" => Fog::Boolean,
"cloudstackversion" => String,
"userpublictemplateenabled" => Fog::Boolean
}
HYPERVISORS = [{
"name"=>String
}]
ZONES = [{
"id"=>Integer,
"name"=>String,
"networktype"=>String,
"securitygroupsenabled"=>Fog::Boolean
}]
NETWORK_OFFERINGS = [{
"id"=>Integer,
"name"=>String,
"displaytext"=>String,
"traffictype"=>String,
"isdefault"=>Fog::Boolean,
"specifyvlan"=>Fog::Boolean,
"availability"=>String,
"guestiptype"=>String,
"networkrate"=>Integer
}]
RESOURCE_LIMITS = [{
"account"=>String,
"domainid"=>Integer,
"domain"=>String,
"resourcetype"=>String,
"max"=>Integer
}]
end
end
end
end

View File

@ -0,0 +1,56 @@
Shindo.tests('Ninfold::Compute | list only requests', ['ninefold']) do
tests('success') do
tests("#list_accounts()").formats(Ninefold::Compute::Formats::Lists::ACCOUNTS) do
pending if Fog.mocking?
Ninefold[:compute].list_accounts
end
tests("#list_events()").formats(Ninefold::Compute::Formats::Lists::EVENTS) do
pending if Fog.mocking?
Ninefold[:compute].list_events
end
tests("#list_service_offerings()").formats(Ninefold::Compute::Formats::Lists::SERVICE_OFFERINGS) do
pending if Fog.mocking?
Ninefold[:compute].list_service_offerings
end
tests("#list_disk_offerings()").formats(Ninefold::Compute::Formats::Lists::DISK_OFFERINGS) do
pending if Fog.mocking?
Ninefold[:compute].list_disk_offerings
end
tests("#list_capabilities()").formats(Ninefold::Compute::Formats::Lists::CAPABILITIES) do
pending if Fog.mocking?
Ninefold[:compute].list_capabilities
end
tests("#list_hypervisors()").formats(Ninefold::Compute::Formats::Lists::HYPERVISORS) do
pending if Fog.mocking?
Ninefold[:compute].list_hypervisors
end
tests("#list_zones()").formats(Ninefold::Compute::Formats::Lists::ZONES) do
pending if Fog.mocking?
Ninefold[:compute].list_zones
end
tests("#list_network_offerings()").formats(Ninefold::Compute::Formats::Lists::NETWORK_OFFERINGS) do
pending if Fog.mocking?
Ninefold[:compute].list_network_offerings
end
tests("#list_resource_limits()").formats(Ninefold::Compute::Formats::Lists::RESOURCE_LIMITS) do
pending if Fog.mocking?
Ninefold[:compute].list_resource_limits
end
end
tests('failure') do
end
end