Class: UnitHosting::VmGroup

Inherits:
Base
  • Object
show all
Defined in:
lib/unit_hosting/vm_group.rb

Instance Attribute Summary

Attributes inherited from Base

#instance_id

Instance Method Summary collapse

Methods inherited from Base

load, #load, #load_key, #server_call

Constructor Details

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

Returns a new instance of VmGroup.



8
9
10
11
12
# File 'lib/unit_hosting/vm_group.rb', line 8

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

Instance Method Details

#create_vm(recipe) ⇒ Object

vmの作成



31
32
33
34
35
# File 'lib/unit_hosting/vm_group.rb', line 31

def create_vm(recipe)
  r = server_call("vmGroup.createVm",recipe.params)
  return false if r["result"] != "success"
  r
end

#vm(instance_id) ⇒ Object

instance_idに紐づくvmを返す



27
28
29
# File 'lib/unit_hosting/vm_group.rb', line 27

def vm(instance_id)
  Vm.new(instance_id,vm_api_key(instance_id))
end

#vm_api_key(instance_id) ⇒ Object



21
22
23
24
25
# File 'lib/unit_hosting/vm_group.rb', line 21

def vm_api_key instance_id
  server_call("vmGroup.getVms").each do |vm|
    return vm["api_key"] if vm[instance_id] == instance_id
  end
end

#vmsObject

このサーバグループに含まれるVMオブジェクトをすべて返す



14
15
16
17
18
19
20
# File 'lib/unit_hosting/vm_group.rb', line 14

def vms
  objs = Hash.new
  server_call("vmGroup.getVms").each do |vm|
    objs[vm["instance_id"]] = Vm.new(vm["instance_id"],vm["api_key"])
  end
  objs
end