mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
network request, parser and model implemented
This commit is contained in:
parent
fa07b49839
commit
dca7193300
8 changed files with 192 additions and 5 deletions
|
@ -53,6 +53,8 @@ module Fog
|
|||
collection :vms
|
||||
model :vm_customization
|
||||
collection :vm_customizations
|
||||
model :network
|
||||
collection :networks
|
||||
|
||||
request_path 'fog/vcloudng/requests/compute'
|
||||
request :get_organizations
|
||||
|
@ -67,6 +69,7 @@ module Fog
|
|||
request :get_task
|
||||
request :get_tasks_list
|
||||
request :get_vm_customization
|
||||
request :get_network
|
||||
|
||||
|
||||
|
||||
|
|
26
lib/fog/vcloudng/models/compute/network.rb
Normal file
26
lib/fog/vcloudng/models/compute/network.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
|
||||
class Network < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :type
|
||||
attribute :href
|
||||
attribute :description
|
||||
attribute :is_inherited
|
||||
attribute :gateway
|
||||
attribute :netmask
|
||||
attribute :dns1
|
||||
attribute :dns2
|
||||
attribute :dns_suffix
|
||||
attribute :ip_ranges, :type => :array
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
46
lib/fog/vcloudng/models/compute/networks.rb
Normal file
46
lib/fog/vcloudng/models/compute/networks.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/vcloudng/models/compute/network'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
|
||||
class Networks < Fog::Collection
|
||||
model Fog::Compute::Vcloudng::Network
|
||||
|
||||
attribute :organization
|
||||
|
||||
def index(organization_id = organization.id)
|
||||
network_links(organization_id).map{ |network| new(network)}
|
||||
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)}
|
||||
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
|
||||
end
|
||||
end
|
|
@ -23,6 +23,11 @@ module Fog
|
|||
service.catalogs(:organization => self)
|
||||
end
|
||||
|
||||
def networks
|
||||
requires :id
|
||||
service.networks(:organization => self)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,6 +28,7 @@ module Fog
|
|||
service.vapps(:vdc => self)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,6 @@ module Fog
|
|||
def customization
|
||||
data = service.get_vm_customization(id).body
|
||||
puts data
|
||||
#VmCustomization.new(data)
|
||||
service.vm_customizations.new(data)
|
||||
end
|
||||
|
||||
|
|
108
lib/fog/vcloudng/parsers/compute/network.rb
Normal file
108
lib/fog/vcloudng/parsers/compute/network.rb
Normal file
|
@ -0,0 +1,108 @@
|
|||
#
|
||||
#{:xmlns=>"http://www.vmware.com/vcloud/v1.5",
|
||||
# :xmlns_xsi=>"http://www.w3.org/2001/XMLSchema-instance",
|
||||
# :name=>"DevOps - Dev Network Connection",
|
||||
# :id=>"urn:vcloud:network:d5f47bbf-de27-4cf5-aaaa-56772f2ccd17",
|
||||
# :type=>"application/vnd.vmware.vcloud.orgNetwork+xml",
|
||||
# :href=>
|
||||
# "https://devlab.mdsol.com/api/network/d5f47bbf-de27-4cf5-aaaa-56772f2ccd17",
|
||||
# :xsi_schemaLocation=>
|
||||
# "http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd",
|
||||
# :Link=>
|
||||
# [{:rel=>"up",
|
||||
# :type=>"application/vnd.vmware.vcloud.org+xml",
|
||||
# :name=>"DevOps",
|
||||
# :href=>
|
||||
# "https://devlab.mdsol.com/api/org/c6a4c623-c158-41cf-a87a-dbc1637ad55a"},
|
||||
# {:rel=>"down",
|
||||
# :type=>"application/vnd.vmware.vcloud.metadata+xml",
|
||||
# :href=>
|
||||
# "https://devlab.mdsol.com/api/network/d5f47bbf-de27-4cf5-aaaa-56772f2ccd17/metadata"}],
|
||||
# :Description=>"",
|
||||
# :Configuration=>
|
||||
# {:IpScope=>
|
||||
# {:IsInherited=>"true",
|
||||
# :Gateway=>"10.192.0.1",
|
||||
# :Netmask=>"255.255.252.0",
|
||||
# :Dns1=>"10.192.0.11",
|
||||
# :Dns2=>"10.192.0.12",
|
||||
# :DnsSuffix=>"dev.ad.mdsol.com",
|
||||
# :IpRanges=>
|
||||
# {:IpRange=>
|
||||
# {:StartAddress=>"10.192.0.100", :EndAddress=>"10.192.3.254"}}},
|
||||
# :FenceMode=>"bridged",
|
||||
# :RetainNetInfoAcrossDeployments=>"false"}}
|
||||
#
|
||||
#<?xml version="1.0" encoding="UTF-8"?>
|
||||
#<OrgNetwork xmlns="http://www.vmware.com/vcloud/v1.5" name="DevOps - Dev Network Connection" id="urn:vcloud:network:d5f47bbf-de27-4cf5-aaaa-56772f2ccd17" type="application/vnd.vmware.vcloud.orgNetwork+xml" href="https://devlab.mdsol.com/api/network/d5f47bbf-de27-4cf5-aaaa-56772f2ccd17" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd">
|
||||
# <Link rel="up" type="application/vnd.vmware.vcloud.org+xml" name="DevOps" href="https://devlab.mdsol.com/api/org/c6a4c623-c158-41cf-a87a-dbc1637ad55a"/>
|
||||
# <Link rel="down" type="application/vnd.vmware.vcloud.metadata+xml" href="https://devlab.mdsol.com/api/network/d5f47bbf-de27-4cf5-aaaa-56772f2ccd17/metadata"/>
|
||||
# <Description/>
|
||||
# <Configuration>
|
||||
# <IpScope>
|
||||
# <IsInherited>true</IsInherited>
|
||||
# <Gateway>10.192.0.1</Gateway>
|
||||
# <Netmask>255.255.252.0</Netmask>
|
||||
# <Dns1>10.192.0.11</Dns1>
|
||||
# <Dns2>10.192.0.12</Dns2>
|
||||
# <DnsSuffix>dev.ad.mdsol.com</DnsSuffix>
|
||||
# <IpRanges>
|
||||
# <IpRange>
|
||||
# <StartAddress>10.192.0.100</StartAddress>
|
||||
# <EndAddress>10.192.3.254</EndAddress>
|
||||
# </IpRange>
|
||||
# </IpRanges>
|
||||
# </IpScope>
|
||||
# <FenceMode>bridged</FenceMode>
|
||||
# <RetainNetInfoAcrossDeployments>false</RetainNetInfoAcrossDeployments>
|
||||
# </Configuration>
|
||||
#</OrgNetwork>
|
||||
#
|
||||
module Fog
|
||||
module Parsers
|
||||
module Compute
|
||||
module Vcloudng
|
||||
|
||||
class Network < VcloudngParser
|
||||
|
||||
def reset
|
||||
@response = { 'ip_ranges' => [] }
|
||||
@ip_range = {}
|
||||
end
|
||||
|
||||
def start_element(name, attributes)
|
||||
super
|
||||
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
|
||||
when 'Description',
|
||||
@response['description'] = value
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'IsInherited'
|
||||
@response['is_inherited'] = (value == "true")
|
||||
when 'Gateway', 'Netmask', 'Dns1', 'Dns2'
|
||||
@response[name.downcase] = value
|
||||
when 'DnsSuffix'
|
||||
@response['dns_suffix'] = value
|
||||
when 'StartAddress'
|
||||
@ip_range['start_address'] = value
|
||||
when 'EndAddress'
|
||||
@ip_range['end_address'] = value
|
||||
when 'IpRange'
|
||||
@response['ip_ranges'] << @ip_range
|
||||
@ip_range = {}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,19 +2,18 @@ module Fog
|
|||
module Compute
|
||||
class Vcloudng
|
||||
class Real
|
||||
|
||||
require 'fog/vcloudng/parsers/compute/network'
|
||||
|
||||
def get_network(network_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:headers => { 'Accept' => 'application/*+xml;version=1.5' },
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:parser => Fog::Parsers::Compute::Vcloudng::Network.new,
|
||||
:path => "network/#{network_id}"
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue