mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[compute|cloudstack] added basic cloudstack list support
This commit is contained in:
parent
2a83d28fb1
commit
5485747ba4
35 changed files with 676 additions and 0 deletions
|
@ -56,6 +56,7 @@ end
|
|||
require 'fog/bin/aws'
|
||||
require 'fog/bin/bluebox'
|
||||
require 'fog/bin/brightbox'
|
||||
require 'fog/bin/cloudstack'
|
||||
require 'fog/bin/dnsimple'
|
||||
require 'fog/bin/dnsmadeeasy'
|
||||
require 'fog/bin/ecloud'
|
||||
|
|
30
lib/fog/bin/cloudstack.rb
Normal file
30
lib/fog/bin/cloudstack.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
class Cloudstack < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :compute
|
||||
Fog::Compute::Cloudstack
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :compute
|
||||
Fog::Compute.new(:provider => 'Cloudstack')
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key.inspect}"
|
||||
end
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
||||
def services
|
||||
Fog::Cloudstack.services
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -17,6 +17,9 @@ module Fog
|
|||
when :brightbox
|
||||
require 'fog/compute/brightbox'
|
||||
Fog::Compute::Brightbox.new(attributes)
|
||||
when :cloudstack
|
||||
require 'fog/compute/cloudstack'
|
||||
Fog::Compute::Cloudstack.new(attributes)
|
||||
when :ecloud
|
||||
require 'fog/compute/ecloud'
|
||||
Fog::Compute::Ecloud.new(attributes)
|
||||
|
|
111
lib/fog/compute/cloudstack.rb
Normal file
111
lib/fog/compute/cloudstack.rb
Normal file
|
@ -0,0 +1,111 @@
|
|||
require 'json'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Cloudstack < Fog::Service
|
||||
|
||||
requires :cloudstack_api_key, :cloudstack_secret_access_key, :host
|
||||
recognizes :host, :port, :path, :scheme, :persistent
|
||||
|
||||
request_path 'fog/compute/requests/cloudstack'
|
||||
|
||||
request :list_accounts
|
||||
request :list_alerts
|
||||
request :list_async_jobs
|
||||
request :list_disk_offerings
|
||||
request :list_domains
|
||||
request :list_events
|
||||
request :list_external_firewalls
|
||||
request :list_external_load_balancers
|
||||
request :list_hosts
|
||||
request :list_hypervisors
|
||||
request :list_instance_groups
|
||||
request :list_isos
|
||||
request :list_network_offerings
|
||||
request :list_networks
|
||||
request :list_os_categories
|
||||
request :list_os_types
|
||||
request :list_pods
|
||||
request :list_resource_limits
|
||||
request :list_security_groups
|
||||
request :list_service_offerings
|
||||
request :list_snapshots
|
||||
request :list_ssh_key_pairs
|
||||
request :list_storage_pools
|
||||
request :list_templates
|
||||
request :list_usage_records
|
||||
request :list_users
|
||||
request :list_virtual_machines
|
||||
request :list_volumes
|
||||
request :list_zones
|
||||
|
||||
|
||||
class Mock
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {}
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@data = nil
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@cloudstack_api_key = options[:cloudstack_api_key]
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data[@cloudstack_api_key]
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.data.delete(@cloudstack_api_key)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
|
||||
def initialize(options={})
|
||||
@cloudstack_api_key = options[:cloudstack_api_key]
|
||||
@cloudstack_secret_access_key = options[:cloudstack_secret_access_key]
|
||||
@host = options[:host]
|
||||
@path = options[:path] || '/client/api'
|
||||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent])
|
||||
end
|
||||
|
||||
def reload
|
||||
@connection.reset
|
||||
end
|
||||
|
||||
def request(params)
|
||||
params.merge!({
|
||||
'apiKey' => @cloudstack_api_key,
|
||||
'response' => 'json'
|
||||
})
|
||||
|
||||
signature = Fog::Cloudstack.signed_params(@cloudstack_secret_access_key,params)
|
||||
|
||||
params.merge!({'signature' => signature})
|
||||
|
||||
response = @connection.request({
|
||||
:query => params,
|
||||
:method => 'GET',
|
||||
:expects => 200
|
||||
})
|
||||
|
||||
unless response.body.empty?
|
||||
response = JSON.parse(response.body)
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_accounts.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_accounts.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_accounts(options={})
|
||||
options.merge!(
|
||||
'command' => 'listAccounts'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_alerts.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_alerts.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_alerts(options={})
|
||||
options.merge!(
|
||||
'command' => 'listAlerts'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_async_jobs.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_async_jobs.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_async_jobs(options={})
|
||||
options.merge!(
|
||||
'command' => 'listAsyncJobs'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_disk_offerings.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_disk_offerings.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_disk_offerings(options={})
|
||||
options.merge!(
|
||||
'command' => 'listDiskOfferings'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_domains.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_domains.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_domains(options={})
|
||||
options.merge!(
|
||||
'command' => 'listDomains'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_events.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_events.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_events(options={})
|
||||
options.merge!(
|
||||
'command' => 'listEvents'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_external_firewalls(options={})
|
||||
options.merge!(
|
||||
'command' => 'listExternalFirewalls'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_external_load_balancers(options={})
|
||||
options.merge!(
|
||||
'command' => 'listExternalLoadBalancers'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_hosts.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_hosts.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_hosts(options={})
|
||||
options.merge!(
|
||||
'command' => 'listHosts'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_hypervisors.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_hypervisors.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_hypervisors(options={})
|
||||
options.merge!(
|
||||
'command' => 'listHypervisors'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_instance_groups.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_instance_groups.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_instance_groups(options={})
|
||||
options.merge!(
|
||||
'command' => 'listInstanceGroups'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_isos.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_isos.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_isos(options={})
|
||||
options.merge!(
|
||||
'command' => 'listIsos'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_network_offerings(options={})
|
||||
options.merge!(
|
||||
'command' => 'listNetworkOfferings'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_networks.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_networks.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_networks(options={})
|
||||
options.merge!(
|
||||
'command' => 'listNetworks'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
lib/fog/compute/requests/cloudstack/list_os_categories.rb
Normal file
19
lib/fog/compute/requests/cloudstack/list_os_categories.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_os_categories(options={})
|
||||
options.merge!(
|
||||
'command' => 'listOsCategories'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
19
lib/fog/compute/requests/cloudstack/list_os_types.rb
Normal file
19
lib/fog/compute/requests/cloudstack/list_os_types.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_os_types(options={})
|
||||
options.merge!(
|
||||
'command' => 'listOsTypes'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
17
lib/fog/compute/requests/cloudstack/list_pods.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_pods.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_pods(options={})
|
||||
options.merge!(
|
||||
'command' => 'listPods'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_resource_limits.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_resource_limits.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_resource_limits(options={})
|
||||
options.merge!(
|
||||
'command' => 'listResourceLimits'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_security_groups.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_security_groups.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_security_groups(options={})
|
||||
options.merge!(
|
||||
'command' => 'listSecurityGroups'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_service_offerings(options={})
|
||||
options.merge!(
|
||||
'command' => 'listServiceOfferings'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_snapshots.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_snapshots.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_snapshots(options={})
|
||||
options.merge!(
|
||||
'command' => 'listSnapshots'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_ssh_key_pairs.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_ssh_key_pairs.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_ssh_key_pairs(options={})
|
||||
options.merge!(
|
||||
'command' => 'listSSHKeyPairs'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_storage_pools.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_storage_pools.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_storage_pools(options={})
|
||||
options.merge!(
|
||||
'command' => 'listStoragePools'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_templates.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_templates.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_templates(options={})
|
||||
options.merge!(
|
||||
'command' => 'listTemplates'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/compute/requests/cloudstack/list_usage_records.rb
Normal file
25
lib/fog/compute/requests/cloudstack/list_usage_records.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_usage_records(options={})
|
||||
options.merge!(
|
||||
'command' => 'listUsageRecords'
|
||||
)
|
||||
|
||||
if startdate = options.delete('startdate')
|
||||
options.merge!('startdate' => startdate.strftime('%Y-%m-%d'))
|
||||
end
|
||||
|
||||
if enddate = options.delete('enddate')
|
||||
options.merge!('enddate' => enddate.strftime('%Y-%m-%d'))
|
||||
end
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_users.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_users.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_users(options={})
|
||||
options.merge!(
|
||||
'command' => 'listUsers'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_virtual_machines.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_virtual_machines.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_virtual_machines(options={})
|
||||
options.merge!(
|
||||
'command' => 'listVirtualMachines'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_volumes.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_volumes.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_volumes(options={})
|
||||
options.merge!(
|
||||
'command' => 'listVolumes'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/compute/requests/cloudstack/list_zones.rb
Normal file
17
lib/fog/compute/requests/cloudstack/list_zones.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Real
|
||||
|
||||
def list_zones(options={})
|
||||
options.merge!(
|
||||
'command' => 'listZones'
|
||||
)
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,6 +9,7 @@ end
|
|||
require 'fog/providers/aws'
|
||||
require 'fog/providers/bluebox'
|
||||
require 'fog/providers/brightbox'
|
||||
require 'fog/providers/cloudstack'
|
||||
require 'fog/providers/dnsimple'
|
||||
require 'fog/providers/dnsmadeeasy'
|
||||
require 'fog/providers/ecloud'
|
||||
|
|
25
lib/fog/providers/cloudstack.rb
Normal file
25
lib/fog/providers/cloudstack.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'fog/core'
|
||||
|
||||
module Fog
|
||||
module Cloudstack
|
||||
|
||||
extend Fog::Provider
|
||||
|
||||
service(:compute, 'compute/cloudstack')
|
||||
|
||||
DIGEST = OpenSSL::Digest::Digest.new('sha1')
|
||||
|
||||
def self.escape(string)
|
||||
CGI::escape(string)
|
||||
end
|
||||
|
||||
def self.signed_params(key,params)
|
||||
query = params.to_a.sort.collect{|c| "#{c[0]}=#{escape(c[1])}"}.join('&').downcase
|
||||
|
||||
signed_string = Base64.encode64(OpenSSL::HMAC.digest(DIGEST,key,query)).strip
|
||||
|
||||
signed_string
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Add table
Reference in a new issue