Class: UnitHosting::Api::Vm

Inherits:
Base
  • Object
show all
Defined in:
lib/unit-hosting/api/vm.rb

Instance Attribute Summary

Attributes inherited from Base

#api_key, #instance_id, #server

Instance Method Summary collapse

Methods inherited from Base

load, #load, #load_key, #server_call

Constructor Details

#initialize(instance_id = nil, api_key = nil) ⇒ Vm

Returns a new instance of Vm.



9
10
11
12
13
# File 'lib/unit-hosting/api/vm.rb', line 9

def initialize(instance_id=nil,api_key=nil)
  @instance_id_elm = '/server/instance_id'
  @api_key_elm = '/server/key'
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/unit-hosting/api/vm.rb', line 19

def method_missing(name, *args)
  name = name.to_s
  name = if /(.*)\?$/ =~ name
           "get#{$1.camelize}"
         else
           name.camelize(:lower)
         end
  if args.blank?
    server_call(to_api(name))
  else
    server_call(to_api(name),*args)
  end
end

Instance Method Details

#cpu_unit_num(num) ⇒ Object



36
37
38
# File 'lib/unit-hosting/api/vm.rb', line 36

def cpu_unit_num num
  server_call("vm.setCpuUnitNum",{"num" => num})
end

#display_nameObject



42
43
44
# File 'lib/unit-hosting/api/vm.rb', line 42

def display_name
  server_call("vm.getDisplayName")
end

#display_name=(name) ⇒ Object



45
46
47
# File 'lib/unit-hosting/api/vm.rb', line 45

def display_name= name
  server_call("vm.setDisplayName",{"display_name" => name})
end

#get_pv_argsObject



69
70
71
# File 'lib/unit-hosting/api/vm.rb', line 69

def get_pv_args
  server_call("vm.getPvArgs")
end

#get_vm_data(key) ⇒ Object



63
64
65
# File 'lib/unit-hosting/api/vm.rb', line 63

def get_vm_data(key)
  server_call("vm.getVmData",{"key" =>key})
end

#ipsObject



39
40
41
# File 'lib/unit-hosting/api/vm.rb', line 39

def ips
  server_call("vm.getIpInfo")
end

#memory_unit_size(size) ⇒ Object



33
34
35
# File 'lib/unit-hosting/api/vm.rb', line 33

def memory_unit_size size
  server_call("vm.setMemoryUnitSize",{"size" => size})
end

#plugVif(network, device = nil) ⇒ Object



51
52
53
# File 'lib/unit-hosting/api/vm.rb', line 51

def plugVif network,device = nil
  server_call("vm.plugVif",{"network_uuid" => network,"device" => device})
end

#replicate(name = "") ⇒ Object



48
49
50
# File 'lib/unit-hosting/api/vm.rb', line 48

def replicate name=""
  server_call("vm.replicate",{"display_name" => name})
end

#set_pv_args(val) ⇒ Object



66
67
68
# File 'lib/unit-hosting/api/vm.rb', line 66

def set_pv_args(val)
  server_call("vm.setPvArgs",{"pv_args" =>val})
end

#set_vm_data(key, val) ⇒ Object



60
61
62
# File 'lib/unit-hosting/api/vm.rb', line 60

def set_vm_data(key,val)
  server_call("vm.setVmData",{"key" =>key,"value" =>val})
end

#to_api(name) ⇒ Object



15
16
17
# File 'lib/unit-hosting/api/vm.rb', line 15

def to_api(name)
  "vm.#{name}"
end

#unplugVif(vif_uuid) ⇒ Object



57
58
59
# File 'lib/unit-hosting/api/vm.rb', line 57

def unplugVif vif_uuid
  server_call("vm.unplugVif",{"vif_uuid" => vif_uuid})
end

#vifsObject



54
55
56
# File 'lib/unit-hosting/api/vm.rb', line 54

def vifs
  server_call("vm.getVifs")
end