1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/vcloudng/models/compute/vms.rb

54 lines
1.1 KiB
Ruby
Raw Normal View History

2013-06-24 13:46:30 +02:00
require 'fog/core/collection'
require 'fog/vcloudng/models/compute/vm'
module Fog
module Compute
class Vcloudng
class Vms < Fog::Collection
model Fog::Compute::Vcloudng::Vm
2013-06-26 16:19:39 +02:00
attribute :vapp_id
2013-06-24 13:46:30 +02:00
2013-06-26 14:23:54 +02:00
def index
vm_links.map{ |vm| new(vm)}
2013-06-24 13:46:30 +02:00
end
2013-06-26 14:23:54 +02:00
def all
index
2013-06-24 13:46:30 +02:00
end
2013-06-26 14:23:54 +02:00
def get(vm_id)
2013-06-26 16:19:39 +02:00
vm = vm_links.detect{ |vm| vm['id'] == vm_id}
return nil unless vm
new(vm)
2013-06-24 13:46:30 +02:00
end
2013-06-26 14:23:54 +02:00
def get_by_name(vm_name)
2013-06-26 16:19:39 +02:00
vm = vm_links.detect{ |vm| vm['name'] == vm_name}
return nil unless vm
2013-06-24 13:46:30 +02:00
new(vm)
end
2013-06-26 14:23:54 +02:00
#def new(attributes = {})
# puts attributes
# puts attributes.class
# if vapp
# puts "there is a vapp #{vapp.inspect}"
# super({ :vapp => vapp }.merge!(attributes))
# else
# super(attributes)
# end
#end
2013-06-26 16:19:39 +02:00
# private
2013-06-24 13:46:30 +02:00
2013-06-26 14:23:54 +02:00
def vm_links
2013-06-26 16:19:39 +02:00
data = service.get_vms(vapp_id).body
2013-06-24 13:46:30 +02:00
data['vms']
end
end
end
end
end