1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

refactor to user vcloud classes

This commit is contained in:
Rodrigo Estebanez 2013-07-09 15:01:06 +02:00
parent 8947cf5a6f
commit c774ddf65e
3 changed files with 25 additions and 39 deletions

View file

@ -4,7 +4,7 @@ module Fog
module Compute module Compute
class Vcloudng class Vcloudng
class Network < Fog::Model class Network < Model
identity :id identity :id

View file

@ -5,40 +5,26 @@ module Fog
module Compute module Compute
class Vcloudng class Vcloudng
class Networks < Fog::Collection class Networks < Collection
model Fog::Compute::Vcloudng::Network model Fog::Compute::Vcloudng::Network
attribute :organization attribute :organization
def index(organization_id = organization.id) private
network_links(organization_id).map{ |network| new(network)}
end def get_by_id(item_id)
item = service.get_network(item_id).body
def all(organization_id = organization.id) service.add_id_from_href!(item)
network_ids = network_links(organization_id).map {|network| network[:id] } item
network_ids.map{ |network_id| get(network_id)}
end end
def get(network_id) def item_list
data = service.get_network(network_id).body data = service.get_organization(organization.id).body
new(data) items = data[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.orgNetwork+xml" }
end items.each{|item| service.add_id_from_href!(item) }
items
def get_by_name(network_name, organization_id = organization.id)
network = network_links(organization_id).detect{|network_link| network_link[:name] == network_name }
return nil unless network
network_id = network[:id]
get(network_id)
end
# private
def network_links(organization_id)
data = service.get_organization(organization_id).body
networks = data[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.orgNetwork+xml" }
networks.each{|network| network[:id] = network[:href].split('/').last }
networks
end end
end end
end end

View file

@ -66,7 +66,7 @@ module Fog
class Network < VcloudngParser class Network < VcloudngParser
def reset def reset
@response = { 'ip_ranges' => [] } @response = { :ip_ranges => [] }
@ip_range = {} @ip_range = {}
end end
@ -75,27 +75,27 @@ module Fog
case name case name
when 'OrgNetwork' when 'OrgNetwork'
network = extract_attributes(attributes) network = extract_attributes(attributes)
@response.merge!(network.reject {|key,value| !['href', 'name', 'type'].include?(key)}) @response.merge!(network.reject {|key,value| ![:href, :name, :type].include?(key)})
@response['id'] = @response['href'].split('/').last @response[:id] = @response[:href].split('/').last
when 'Description', when 'Description',
@response['description'] = value @response[:description] = value
end end
end end
def end_element(name) def end_element(name)
case name case name
when 'IsInherited' when 'IsInherited'
@response['is_inherited'] = (value == "true") @response[:is_inherited] = (value == "true")
when 'Gateway', 'Netmask', 'Dns1', 'Dns2' when 'Gateway', 'Netmask', 'Dns1', 'Dns2'
@response[name.downcase] = value @response[name.downcase.to_sym] = value
when 'DnsSuffix' when 'DnsSuffix'
@response['dns_suffix'] = value @response[:dns_suffix] = value
when 'StartAddress' when 'StartAddress'
@ip_range['start_address'] = value @ip_range[:start_address] = value
when 'EndAddress' when 'EndAddress'
@ip_range['end_address'] = value @ip_range[:end_address] = value
when 'IpRange' when 'IpRange'
@response['ip_ranges'] << @ip_range @response[:ip_ranges] << @ip_range
@ip_range = {} @ip_range = {}
end end
end end