mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
network and networks model implemented
This commit is contained in:
parent
74c9f0800e
commit
346fe644bb
8 changed files with 352 additions and 1 deletions
|
@ -57,6 +57,8 @@ module Fog
|
|||
collection :networks
|
||||
model :disk
|
||||
collection :disks
|
||||
model :vm_network
|
||||
collection :vm_networks
|
||||
|
||||
request_path 'fog/vcloudng/requests/compute'
|
||||
request :get_organizations
|
||||
|
@ -80,8 +82,10 @@ module Fog
|
|||
request :get_request
|
||||
request :get_vm_disks
|
||||
request :put_vm_disks
|
||||
request :get_vm_network
|
||||
request :put_vm_network
|
||||
|
||||
|
||||
|
||||
|
||||
class Real
|
||||
include Fog::Compute::Helper
|
||||
|
@ -158,6 +162,8 @@ module Fog
|
|||
:path => path
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
122
lib/fog/vcloudng/generators/compute/vm_network.rb
Normal file
122
lib/fog/vcloudng/generators/compute/vm_network.rb
Normal file
|
@ -0,0 +1,122 @@
|
|||
# This is the data structure it accepts, this is the output of get_vm_network
|
||||
#
|
||||
# {:type=>"application/vnd.vmware.vcloud.networkConnectionSection+xml",
|
||||
# :href=>
|
||||
# "https://devlab.mdsol.com/api/vApp/vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae/networkConnectionSection/",
|
||||
# :id=>"vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae",
|
||||
# :primary_network_connection_index=>0,
|
||||
# :network=>"DevOps - Dev Network Connection",
|
||||
# :needs_customization=>true,
|
||||
# :network_connection_index=>0,
|
||||
# :ip_address=>"10.192.0.130",
|
||||
# :is_connected=>true,
|
||||
# :mac_address=>"00:50:56:01:00:8d",
|
||||
# :ip_address_allocation_mode=>"POOL"}
|
||||
#
|
||||
#
|
||||
# This is what it generates
|
||||
#
|
||||
# <NetworkConnectionSection xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" type="application/vnd.vmware.vcloud.networkConnectionSection+xml" href="https://devlab.mdsol.com/api/vApp/vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae/networkConnectionSection/" ovf:required="false" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd">
|
||||
# <ovf:Info>Specifies the available VM network connections</ovf:Info>
|
||||
# <PrimaryNetworkConnectionIndex>0</PrimaryNetworkConnectionIndex>
|
||||
# <NetworkConnection network="DevOps - Dev Network Connection" needsCustomization="true">
|
||||
# <NetworkConnectionIndex>0</NetworkConnectionIndex>
|
||||
# <IpAddress>10.192.0.130</IpAddress>
|
||||
# <IsConnected>true</IsConnected>
|
||||
# <MACAddress>00:50:56:01:00:8d</MACAddress>
|
||||
# <IpAddressAllocationMode>POOL</IpAddressAllocationMode>
|
||||
# </NetworkConnection>
|
||||
# <Link rel="edit" type="application/vnd.vmware.vcloud.networkConnectionSection+xml" href="https://devlab.mdsol.com/api/vApp/vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae/networkConnectionSection/"/>
|
||||
# </NetworkConnectionSection>
|
||||
#
|
||||
module Fog
|
||||
module Generators
|
||||
module Compute
|
||||
module Vcloudng
|
||||
|
||||
class VmNetwork
|
||||
|
||||
attr_reader :attrs
|
||||
|
||||
def initialize(attrs={})
|
||||
@attrs = attrs
|
||||
end
|
||||
|
||||
def generate_xml
|
||||
output = ""
|
||||
output << header
|
||||
output << body(@attrs)
|
||||
output << tail
|
||||
output
|
||||
end
|
||||
|
||||
def network
|
||||
@attrs[:network]
|
||||
end
|
||||
|
||||
def network=(new_network_name)
|
||||
@attrs[:network] = new_network_name
|
||||
end
|
||||
|
||||
def ip_address
|
||||
@attrs[:ip_address]
|
||||
end
|
||||
|
||||
def ip_address=(new_ip_address)
|
||||
@attrs[:ip_address] = new_ip_address
|
||||
end
|
||||
|
||||
def is_connected
|
||||
@attrs[:is_connected]
|
||||
end
|
||||
|
||||
def is_connected=(new_is_connected)
|
||||
@attrs[:is_connected] = new_is_connected
|
||||
end
|
||||
|
||||
def ip_address_allocation_mode
|
||||
@attrs[:ip_address_allocation_mode]
|
||||
end
|
||||
|
||||
def ip_address_allocation_mode=(new_ip_address_allocation_mode)
|
||||
@attrs[:ip_address_allocation_mode] = new_ip_address_allocation_mode
|
||||
end
|
||||
|
||||
def header
|
||||
'<NetworkConnectionSection xmlns="http://www.vmware.com/vcloud/v1.5"
|
||||
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
type="application/vnd.vmware.vcloud.networkConnectionSection+xml"
|
||||
ovf:required="false"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1
|
||||
http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd
|
||||
http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd">'
|
||||
|
||||
end
|
||||
|
||||
|
||||
def body(opts={})
|
||||
body = <<EOF
|
||||
<ovf:Info>#{opts[:info]}</ovf:Info>
|
||||
<PrimaryNetworkConnectionIndex>#{opts[:primary_network_connection_index]}</PrimaryNetworkConnectionIndex>
|
||||
<NetworkConnection
|
||||
network="#{opts[:network]}"
|
||||
needsCustomization="#{opts[:needs_customization]}">
|
||||
<NetworkConnectionIndex>#{opts[:network_connection_index]}</NetworkConnectionIndex>
|
||||
<IpAddress>#{opts[:ip_address]}</IpAddress>
|
||||
<IsConnected>#{opts[:is_connected]}</IsConnected>
|
||||
<MACAddress>#{opts[:mac_address]}</MACAddress>
|
||||
<IpAddressAllocationMode>#{opts[:ip_address_allocation_mode]}</IpAddressAllocationMode>
|
||||
</NetworkConnection>
|
||||
EOF
|
||||
end
|
||||
|
||||
def tail
|
||||
'</NetworkConnectionSection>'
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -25,6 +25,11 @@ module Fog
|
|||
service.vm_customizations.new(data)
|
||||
end
|
||||
|
||||
def network
|
||||
data = service.get_vm_network(id).body
|
||||
service.vm_networks.new(data)
|
||||
end
|
||||
|
||||
def disks
|
||||
requires :id
|
||||
service.disks(:vm_id => id)
|
||||
|
|
45
lib/fog/vcloudng/models/compute/vm_network.rb
Normal file
45
lib/fog/vcloudng/models/compute/vm_network.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
|
||||
class VmNetwork < Fog::Model
|
||||
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :type
|
||||
attribute :href
|
||||
attribute :info
|
||||
attribute :primary_network_connection_index
|
||||
attribute :network
|
||||
attribute :needs_customization
|
||||
attribute :network_connection_index
|
||||
attribute :is_connected
|
||||
attribute :mac_address
|
||||
attribute :ip_address_allocation_mode
|
||||
|
||||
def save
|
||||
show_exception_body_error {
|
||||
response = service.put_vm_network(id, attributes)
|
||||
task = response.body
|
||||
task[:id] = task[:href].split('/').last
|
||||
attributes[:network_task] = service.tasks.new(task)
|
||||
}
|
||||
end
|
||||
|
||||
def show_exception_body_error
|
||||
yield
|
||||
rescue => @e
|
||||
raise @e unless @e.class.to_s =~ /^Excon::Errors/
|
||||
puts @e.response.status
|
||||
puts CGI::unescapeHTML(@e.response.body)
|
||||
raise @e
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/vcloudng/models/compute/vm_networks.rb
Normal file
17
lib/fog/vcloudng/models/compute/vm_networks.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/vcloudng/models/compute/vm_network'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
|
||||
class VmNetworks < Fog::Collection
|
||||
model Fog::Compute::Vcloudng::VmNetwork
|
||||
|
||||
attribute :vm
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
111
lib/fog/vcloudng/parsers/compute/vm_network.rb
Normal file
111
lib/fog/vcloudng/parsers/compute/vm_network.rb
Normal file
|
@ -0,0 +1,111 @@
|
|||
#
|
||||
#{: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 VmNetwork < VcloudngParser
|
||||
|
||||
def reset
|
||||
@response = { }
|
||||
end
|
||||
|
||||
def start_element(name, attributes)
|
||||
super
|
||||
case name
|
||||
when 'NetworkConnectionSection'
|
||||
network_connection_section = extract_attributes(attributes)
|
||||
@response[:type] = network_connection_section['type']
|
||||
@response[:href] = network_connection_section['href']
|
||||
@response[:id] = @response[:href].split('/')[-2]
|
||||
when 'NetworkConnection'
|
||||
network_connection = extract_attributes(attributes)
|
||||
@response[:network] = network_connection['network']
|
||||
@response[:needs_customization] = ( network_connection['needsCustomization'] == "true" )
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'Info'
|
||||
@response[:info] = value
|
||||
when 'PrimaryNetworkConnectionIndex'
|
||||
@response[:primary_network_connection_index] = value.to_i
|
||||
when 'NetworkConnectionIndex'
|
||||
@response[:network_connection_index] = value.to_i
|
||||
when 'IpAddress'
|
||||
@response[:ip_address] = value
|
||||
when 'IsConnected'
|
||||
@response[:is_connected] = (value == "true")
|
||||
when 'MACAddress'
|
||||
@response[:mac_address] = value
|
||||
when 'IpAddressAllocationMode'
|
||||
@response[:ip_address_allocation_mode] = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
21
lib/fog/vcloudng/requests/compute/get_vm_network.rb
Normal file
21
lib/fog/vcloudng/requests/compute/get_vm_network.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
class Real
|
||||
|
||||
def get_vm_network(vm_id)
|
||||
require 'fog/vcloudng/parsers/compute/vm_network'
|
||||
|
||||
request(
|
||||
:expects => 200,
|
||||
:headers => { 'Accept' => 'application/*+xml;version=1.5' },
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Compute::Vcloudng::VmNetwork.new,
|
||||
:path => "vApp/#{vm_id}/networkConnectionSection/"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
lib/fog/vcloudng/requests/compute/put_vm_network.rb
Normal file
24
lib/fog/vcloudng/requests/compute/put_vm_network.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
class Real
|
||||
|
||||
def put_vm_network(vm_id, network={})
|
||||
require 'fog/vcloudng/generators/compute/vm_network'
|
||||
|
||||
data = Fog::Generators::Compute::Vcloudng::VmNetwork.new(network)
|
||||
|
||||
request(
|
||||
:body => data.generate_xml,
|
||||
:expects => 202,
|
||||
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.networkConnectionSection+xml',
|
||||
'Accept' => 'application/*+xml;version=1.5' },
|
||||
:method => 'PUT',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "vApp/#{vm_id}/networkConnectionSection/"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue