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
class Vcloudng
class Network < Fog::Model
class Network < Model
identity :id

View file

@ -5,40 +5,26 @@ module Fog
module Compute
class Vcloudng
class Networks < Fog::Collection
class Networks < Collection
model Fog::Compute::Vcloudng::Network
attribute :organization
def index(organization_id = organization.id)
network_links(organization_id).map{ |network| new(network)}
private
def get_by_id(item_id)
item = service.get_network(item_id).body
service.add_id_from_href!(item)
item
end
def all(organization_id = organization.id)
network_ids = network_links(organization_id).map {|network| network[:id] }
network_ids.map{ |network_id| get(network_id)}
def item_list
data = service.get_organization(organization.id).body
items = data[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.orgNetwork+xml" }
items.each{|item| service.add_id_from_href!(item) }
items
end
def get(network_id)
data = service.get_network(network_id).body
new(data)
end
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

View file

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