2013-06-24 07:46:30 -04:00
|
|
|
require 'fog/core/collection'
|
2013-08-27 05:19:54 -04:00
|
|
|
require 'fog/vcloud_director/models/compute/vm'
|
2013-06-24 07:46:30 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
2013-08-27 05:19:54 -04:00
|
|
|
class VcloudDirector
|
2013-06-24 07:46:30 -04:00
|
|
|
|
2013-07-09 09:48:44 -04:00
|
|
|
class Vms < Collection
|
2013-08-27 05:19:54 -04:00
|
|
|
model Fog::Compute::VcloudDirector::Vm
|
2013-09-16 13:13:09 -04:00
|
|
|
|
2013-07-09 09:48:44 -04:00
|
|
|
attribute :vapp
|
2013-09-16 13:13:09 -04:00
|
|
|
|
2013-09-02 05:58:05 -04:00
|
|
|
def get_by_metadata(key, value)
|
|
|
|
data = service.get_vms_by_metadata(key, value).body
|
|
|
|
items = data[:vm_records]
|
|
|
|
load(items)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_single_vm(vm_id)
|
|
|
|
item = service.get_vm(vm_id).body
|
|
|
|
return nil unless item
|
|
|
|
new(item[:vm])
|
|
|
|
end
|
|
|
|
|
2013-06-28 06:49:11 -04:00
|
|
|
private
|
2013-09-16 13:13:09 -04:00
|
|
|
|
2013-07-09 09:48:44 -04:00
|
|
|
def get_by_id(item_id)
|
2013-08-27 08:33:36 -04:00
|
|
|
item = item_list.detect{ |vm| vm[:id] == item_id }
|
2013-07-09 09:48:44 -04:00
|
|
|
item
|
|
|
|
end
|
2013-09-16 13:13:09 -04:00
|
|
|
|
2013-07-09 09:48:44 -04:00
|
|
|
def item_list
|
2013-09-02 05:58:05 -04:00
|
|
|
data = service.get_vms(vapp.id).body # vapp.id
|
2013-07-09 09:48:44 -04:00
|
|
|
items = data[:vms]
|
|
|
|
items
|
2013-06-24 07:46:30 -04:00
|
|
|
end
|
2013-09-16 13:13:09 -04:00
|
|
|
|
2013-06-24 07:46:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-09-16 13:13:09 -04:00
|
|
|
end
|