Class: Fog::Compute::Ninefold::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/compute/ninefold.rb,
lib/fog/compute/requests/ninefold/list_zones.rb,
lib/fog/compute/requests/ninefold/list_events.rb,
lib/fog/compute/requests/ninefold/list_accounts.rb,
lib/fog/compute/requests/ninefold/list_networks.rb,
lib/fog/compute/requests/ninefold/list_templates.rb,
lib/fog/compute/requests/ninefold/list_async_jobs.rb,
lib/fog/compute/requests/ninefold/list_hypervisors.rb,
lib/fog/compute/requests/ninefold/enable_static_nat.rb,
lib/fog/compute/requests/ninefold/list_capabilities.rb,
lib/fog/compute/requests/ninefold/disable_static_nat.rb,
lib/fog/compute/requests/ninefold/list_disk_offerings.rb,
lib/fog/compute/requests/ninefold/associate_ip_address.rb,
lib/fog/compute/requests/ninefold/list_resource_limits.rb,
lib/fog/compute/requests/ninefold/stop_virtual_machine.rb,
lib/fog/compute/requests/ninefold/list_virtual_machines.rb,
lib/fog/compute/requests/ninefold/start_virtual_machine.rb,
lib/fog/compute/requests/ninefold/deploy_virtual_machine.rb,
lib/fog/compute/requests/ninefold/list_network_offerings.rb,
lib/fog/compute/requests/ninefold/list_service_offerings.rb,
lib/fog/compute/requests/ninefold/query_async_job_result.rb,
lib/fog/compute/requests/ninefold/reboot_virtual_machine.rb,
lib/fog/compute/requests/ninefold/update_virtual_machine.rb,
lib/fog/compute/requests/ninefold/destroy_virtual_machine.rb,
lib/fog/compute/requests/ninefold/disassociate_ip_address.rb,
lib/fog/compute/requests/ninefold/list_ip_forwarding_rules.rb,
lib/fog/compute/requests/ninefold/list_public_ip_addresses.rb,
lib/fog/compute/requests/ninefold/create_ip_forwarding_rule.rb,
lib/fog/compute/requests/ninefold/delete_ip_forwarding_rule.rb,
lib/fog/compute/requests/ninefold/change_service_for_virtual_machine.rb,
lib/fog/compute/requests/ninefold/reset_password_for_virtual_machine.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Real

Returns a new instance of Real.



78
79
80
81
82
83
84
85
# File 'lib/fog/compute/ninefold.rb', line 78

def initialize(options)
  require 'multi_json'

  @api_url = options[:ninefold_api_url] || Fog.credentials[:ninefold_api_url] || API_URL
  @ninefold_compute_key = options[:ninefold_compute_key] || Fog.credentials[:ninefold_compute_key]
  @ninefold_compute_secret = options[:ninefold_compute_secret] || Fog.credentials[:ninefold_compute_secret]
  @connection = Fog::Connection.new(@api_url)
end

Instance Method Details

#associate_ip_address(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/associate_ip_address.rb', line 6

def associate_ip_address(options = {})
  request('associateIpAddress', options, :expects => [200],
          :response_prefix => 'associateipaddressresponse', :response_type => Hash)
end

#change_service_for_virtual_machine(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/change_service_for_virtual_machine.rb', line 6

def change_service_for_virtual_machine(options = {})
  request('changeServiceForVirtualMachine', options, :expects => [200],
          :response_prefix => 'changeserviceforvirtualmachineresponse/virtualmachine', :response_type => Hash)
end

#create_ip_forwarding_rule(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/create_ip_forwarding_rule.rb', line 6

def create_ip_forwarding_rule(options = {})
  request('createIpForwardingRule', options, :expects => [200],
          :response_prefix => 'createipforwardingruleresponse', :response_type => Hash)
end

#delete_ip_forwarding_rule(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/delete_ip_forwarding_rule.rb', line 6

def delete_ip_forwarding_rule(options = {})
  request('deleteIpForwardingRule', options, :expects => [200],
          :response_prefix => 'deleteipforwardingruleresponse', :response_type => Hash)
end

#deploy_virtual_machine(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/deploy_virtual_machine.rb', line 6

def deploy_virtual_machine(options = {})
  request('deployVirtualMachine', options, :expects => [200],
          :response_prefix => 'deployvirtualmachineresponse', :response_type => Hash)
end

#destroy_virtual_machine(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/destroy_virtual_machine.rb', line 6

def destroy_virtual_machine(options = {})
  request('destroyVirtualMachine', options, :expects => [200],
          :response_prefix => 'destroyvirtualmachineresponse', :response_type => Hash)
end

#disable_static_nat(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/disable_static_nat.rb', line 6

def disable_static_nat(options = {})
  request('disableStaticNat', options, :expects => [200],
          :response_prefix => 'disablestaticnatresponse', :response_type => Hash)
end

#disassociate_ip_address(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/disassociate_ip_address.rb', line 6

def disassociate_ip_address(options = {})
  request('disassociateIpAddress', options, :expects => [200],
          :response_prefix => 'disassociateipaddressresponse', :response_type => Hash)
end

#enable_static_nat(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/enable_static_nat.rb', line 6

def enable_static_nat(options = {})
  request('enableStaticNat', options, :expects => [200],
          :response_prefix => 'enablestaticnatresponse', :response_type => Hash)
end

#list_accounts(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_accounts.rb', line 6

def list_accounts(options = {})
  request('listAccounts', options, :expects => [200],
          :response_prefix => 'listaccountsresponse/account', :response_type => Array)
end

#list_async_jobs(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_async_jobs.rb', line 6

def list_async_jobs(options = {})
  request('listAsyncJobs', options, :expects => [200],
          :response_prefix => 'listasyncjobsresponse/asyncjobs', :response_type => Array)
end

#list_capabilities(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_capabilities.rb', line 6

def list_capabilities(options = {})
  request('listCapabilities', options, :expects => [200],
          :response_prefix => 'listcapabilitiesresponse/capability', :response_type => Array)
end

#list_disk_offerings(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_disk_offerings.rb', line 6

def list_disk_offerings(options = {})
  request('listDiskOfferings', options, :expects => [200],
          :response_prefix => 'listdiskofferingsresponse/diskoffering', :response_type => Array)
end

#list_events(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_events.rb', line 6

def list_events(options = {})
  request('listEvents', options, :expects => [200],
          :response_prefix => 'listeventsresponse/event', :response_type => Array)
end

#list_hypervisors(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_hypervisors.rb', line 6

def list_hypervisors(options = {})
  request('listHypervisors', options, :expects => [200],
          :response_prefix => 'listhypervisorsresponse/hypervisor', :response_type => Array)
end

#list_ip_forwarding_rules(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_ip_forwarding_rules.rb', line 6

def list_ip_forwarding_rules(options = {})
  request('listIpForwardingRules', options, :expects => [200],
          :response_prefix => 'listipforwardingrulesresponse/ipforwardingrule', :response_type => Hash)
end

#list_network_offerings(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_network_offerings.rb', line 6

def list_network_offerings(options = {})
  request('listNetworkOfferings', options, :expects => [200],
          :response_prefix => 'listnetworkofferingsresponse/networkoffering', :response_type => Array)
end

#list_networks(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_networks.rb', line 6

def list_networks(options = {})
  request('listNetworks', options, :expects => [200],
          :response_prefix => 'listnetworksresponse/network', :response_type => Array)
end

#list_public_ip_addresses(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_public_ip_addresses.rb', line 6

def list_public_ip_addresses(options = {})
  request('listPublicIpAddresses', options, :expects => [200],
          :response_prefix => 'listpublicipaddressesresponse/publicipaddress', :response_type => Hash)
end

#list_resource_limits(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_resource_limits.rb', line 6

def list_resource_limits(options = {})
  request('listResourceLimits', options, :expects => [200],
          :response_prefix => 'listresourcelimitsresponse/resourcelimit', :response_type => Array)
end

#list_service_offerings(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_service_offerings.rb', line 6

def list_service_offerings(options = {})
  request('listServiceOfferings', options, :expects => [200],
          :response_prefix => 'listserviceofferingsresponse/serviceoffering', :response_type => Array)
end

#list_templates(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_templates.rb', line 6

def list_templates(options = {})
  request('listTemplates', options, :expects => [200],
          :response_prefix => 'listtemplatesresponse/template', :response_type => Array)
end

#list_virtual_machines(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_virtual_machines.rb', line 6

def list_virtual_machines(options = {})
  request('listVirtualMachines', options, :expects => [200],
          :response_prefix => 'listvirtualmachinesresponse/virtualmachine', :response_type => Array)
end

#list_zones(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/list_zones.rb', line 6

def list_zones(options = {})
  request('listZones', options, :expects => [200],
          :response_prefix => 'listzonesresponse/zone', :response_type => Array)
end

#query_async_job_result(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/query_async_job_result.rb', line 6

def query_async_job_result(options = {})
  request('queryAsyncJobResult', options, :expects => [200],
          :response_prefix => 'queryasyncjobresultresponse', :response_type => Array)
end

#reboot_virtual_machine(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/reboot_virtual_machine.rb', line 6

def reboot_virtual_machine(options = {})
  request('rebootVirtualMachine', options, :expects => [200],
          :response_prefix => 'rebootvirtualmachineresponse', :response_type => Hash)
end

#request(command, params, options) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fog/compute/ninefold.rb', line 87

def request(command, params, options)
  params['response'] = "json"
  req = "apiKey=#{@ninefold_compute_key}&command=#{command}&"
  # convert params to strings for sort
  req += URI.escape(params.sort_by{|k,v| k.to_s }.collect{|e| "#{e[0].to_s}=#{e[1].to_s}"}.join('&'))
  encoded_signature = url_escape(encode_signature(req))

  options = {
    :expects => 200,
    :method => 'GET',
    :query => "#{req}&signature=#{encoded_signature}"
  }.merge(options)

  begin
    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 = MultiJson.decode(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].new
          break
        else
        end
      end
      response
    else
      response
    end
  end
end

#reset_password_for_virtual_machine(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/reset_password_for_virtual_machine.rb', line 6

def reset_password_for_virtual_machine(options = {})
  request('resetPasswordForVirtualMachine', options, :expects => [200],
          :response_prefix => 'resetpasswordforvirtualmachineresponse', :response_type => Hash)
end

#start_virtual_machine(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/start_virtual_machine.rb', line 6

def start_virtual_machine(options = {})
  request('startVirtualMachine', options, :expects => [200],
          :response_prefix => 'startvirtualmachineresponse', :response_type => Hash)
end

#stop_virtual_machine(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/stop_virtual_machine.rb', line 6

def stop_virtual_machine(options = {})
  request('stopVirtualMachine', options, :expects => [200],
          :response_prefix => 'stopvirtualmachineresponse', :response_type => Hash)
end

#update_virtual_machine(options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/compute/requests/ninefold/update_virtual_machine.rb', line 6

def update_virtual_machine(options = {})
  request('updateVirtualMachine', options, :expects => [200],
          :response_prefix => 'updatevirtualmachineresponse', :response_type => Hash)
end