mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
refactor vdc to use vcloud classes
This commit is contained in:
parent
c774ddf65e
commit
c4b9d0f611
2 changed files with 14 additions and 29 deletions
|
@ -4,7 +4,7 @@ module Fog
|
||||||
module Compute
|
module Compute
|
||||||
class Vcloudng
|
class Vcloudng
|
||||||
|
|
||||||
class Vdc < Fog::Model
|
class Vdc < Model
|
||||||
|
|
||||||
identity :id
|
identity :id
|
||||||
|
|
||||||
|
|
|
@ -5,40 +5,25 @@ module Fog
|
||||||
module Compute
|
module Compute
|
||||||
class Vcloudng
|
class Vcloudng
|
||||||
|
|
||||||
class Vdcs < Fog::Collection
|
class Vdcs < Collection
|
||||||
model Fog::Compute::Vcloudng::Vdc
|
model Fog::Compute::Vcloudng::Vdc
|
||||||
|
|
||||||
attribute :organization
|
attribute :organization
|
||||||
|
|
||||||
def index(organization_id = organization.id)
|
|
||||||
vdc_links(organization_id).map{ |vdc| new(vdc)}
|
|
||||||
end
|
|
||||||
|
|
||||||
def all(organization_id = organization.id)
|
|
||||||
vdc_ids = vdc_links(organization_id).map {|vdc| vdc[:id] }
|
|
||||||
vdc_ids.map{ |vdc_id| get(vdc_id)}
|
|
||||||
end
|
|
||||||
|
|
||||||
def get(vdc_id)
|
|
||||||
data = service.get_vdc(vdc_id).body
|
|
||||||
data[:id] = data[:href].split('/').last
|
|
||||||
%w(:VdcItems :Link :ResourceEntities).each {|key_to_delete| data.delete(key_to_delete) }
|
|
||||||
new(data)
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_by_name(vdc_name, organization_id = organization.id)
|
|
||||||
vdc = vdc_links(organization_id).detect{|vdc_link| vdc_link[:name] == vdc_name }
|
|
||||||
return nil unless vdc
|
|
||||||
get(vdc[:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def vdc_links(organization_id)
|
def get_by_id(item_id)
|
||||||
data = service.get_organization(organization_id).body
|
item = service.get_vdc(item_id).body
|
||||||
vdcs = data[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" }
|
%w(:VdcItems :Link :ResourceEntities).each {|key_to_delete| item.delete(key_to_delete) }
|
||||||
vdcs.each{|vdc| vdc[:id] = vdc[:href].split('/').last }
|
service.add_id_from_href!(item)
|
||||||
vdcs
|
item
|
||||||
|
end
|
||||||
|
|
||||||
|
def item_list
|
||||||
|
data = service.get_organization(organization.id).body
|
||||||
|
items = data[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" }
|
||||||
|
items.each{|item| service.add_id_from_href!(item) }
|
||||||
|
items
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue