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

Merge pull request #2228 from alphagov/vcloud-director_edge-gateway_support

[vcloud_director] Getting Edge Gateways details
This commit is contained in:
Nick Osborn 2013-10-08 13:48:54 -07:00
commit 7b61bd5f5a
5 changed files with 515 additions and 4 deletions

View file

@ -184,6 +184,8 @@ module Fog
request :put_memory
request :put_network_connection_system_section_vapp
request :put_vapp_metadata_item_metadata
request :get_edge_gateways
request :get_edge_gateway
class Model < Fog::Model
def initialize(attrs={})
@ -379,6 +381,11 @@ module Fog
def data
@@data ||= Hash.new do |hash, key|
vdc_uuid = uuid
default_network_uuid = uuid
uplink_network_uuid = uuid
hash[key] = {
:catalogs => {
uuid => {
@ -393,19 +400,55 @@ module Fog
},
:medias => {},
:networks => {
uuid => {
:Description => 'Network for mocking',
default_network_uuid => {
:ApplyRateLimit => "false",
:Description => 'Org Network for mocking',
:Dns1 => '8.8.8.8',
:Dns2 => '8.8.4.4',
:DnsSuffix => 'example.com',
:Gateway => '192.168.1.1',
:InterfaceType => "internal",
:IpRanges => [{
:StartAddress=>'192.168.1.2',
:EndAddress=>'192.168.1.254'
}],
:IsInherited => false,
:Netmask => '255.255.255.0',
:name => 'Default Network'
:name => 'Default Network',
:SubnetParticipation => {
:Gateway => "192.168.1.0",
:Netmask => "255.255.0.0",
:IpAddress => "192.168.1.0"
},
:UseForDefaultRoute => "false"
},
uplink_network_uuid => {
:ApplyRateLimit => "false",
:Description => 'Uplink Network for mocking',
:Dns1 => '8.8.8.8',
:Dns2 => '8.8.4.4',
:DnsSuffix => 'example.com',
:Gateway => '198.51.100.1',
:InterfaceType => "uplink",
:IpRanges => [{
:StartAddress=>'198.51.100.2',
:EndAddress=>'198.51.100.254'
}],
:IsInherited => false,
:Netmask => '255.255.255.0',
:name => 'uplink Network',
:SubnetParticipation => {
:Gateway => "198.51.100.81",
:Netmask => "255.255.255.248",
:IpAddress => "198.51.100.83",
:IpRanges => {
:IpRange => {
:StartAddress => "198.51.100.84",
:EndAddress => "198.51.100.86"
}
}
},
:UseForDefaultRoute => "true"
}
},
:org => {
@ -416,10 +459,17 @@ module Fog
},
:tasks => {},
:vdcs => {
uuid => {
vdc_uuid => {
:description => 'vDC for mocking',
:name => 'MockVDC'
}
},
:edge_gateways => {
uuid => {
:name => 'MockEdgeGateway',
:vdc => vdc_uuid,
:networks => [uplink_network_uuid, default_network_uuid]
}
}
}
end[@vcloud_director_username]

View file

@ -0,0 +1,97 @@
module Fog
module Compute
class VcloudDirector
class Real
# Retrieve an edge gateway
#
# @param [String] id Object identifier of the Edge Gateway
# @return [Excon::Response]
# * body<~Hash>:
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-EdgeGateway.html
# vCloud API Documentation
# @since vCloud API version 5.1
def get_edge_gateway(id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "admin/edgeGateway/#{id}"
)
end
end
class Mock
def get_edge_gateway(id)
response = Excon::Response.new
unless valid_uuid?(id)
response.status = 400
raise Excon::Errors.status_error({:expects => 200}, response)
end
unless edge_gateway = data[:edge_gateways][id]
response.status = 403
raise Excon::Errors.status_error({:expects => 200}, response)
end
vdc_id = edge_gateway[:vdc]
body = {
:xmlns => xmlns,
:xmlns_xsi => xmlns_xsi,
:status => "1",
:name => edge_gateway[:name],
:id => "urn:vcloud:gateway:27805d5d-868b-4678-b30b-11e14ad34eca",
:type => "application/vnd.vmware.admin.edgeGateway+xml",
:href => make_href("admin/edgeGateway/#{id}"),
:xsi_schemaLocation => xsi_schema_location,
:Link =>[{:rel => "up",
:type => "application/vnd.vmware.vcloud.vdc+xml",
:href => make_href("vdc/#{vdc_id}")},
{:rel => "edgeGateway:redeploy",
:href => make_href("admin/edgeGateway/#{id}/action/redeploy")},
{:rel => "edgeGateway:configureServices",
:type => "application/vnd.vmware.admin.edgeGatewayServiceConfiguration+xml",
:href => make_href("admin/edgeGateway/#{id}/action/configureServices")},
{:rel => "edgeGateway:reapplyServices",
:href => make_href("admin/edgeGateway/#{id}/action/reapplyServices")},
{:rel => "edgeGateway:syncSyslogSettings",
:href => make_href("admin/edgeGateway/#{id}/action/syncSyslogServerSettings")}],
:Description => "vCloud CI (nft00052i2)",
:Configuration =>
{:GatewayBackingConfig => "compact",
:GatewayInterfaces =>
{:GatewayInterface => []},
:EdgeGatewayServiceConfiguration =>
{:FirewallService =>
{:IsEnabled => "true",
:DefaultAction => "drop",
:LogDefaultAction => "false"},
:NatService => {:IsEnabled => "true"}},
:HaEnabled => "false",
:UseDefaultRouteForDnsRelay => "false"}}
body[:Configuration][:GatewayInterfaces][:GatewayInterface] += edge_gateway[:networks].map do |network|
extras = {
:Network => {
:type => "application/vnd.vmware.admin.network+xml",
:name => "anything",
:href => make_href("admin/network/#{network}")
},
:Name => data[:networks][network][:name],
:DisplayName => data[:networks][network][:name]
}
data[:networks][network].merge extras
end
response.status = 200
response.headers = {'Content-Type' => "#{body[:type]};version=#{api_version}"}
response.body = body
response
end
end
end
end
end

View file

@ -0,0 +1,79 @@
module Fog
module Compute
class VcloudDirector
class Real
# List all gateways for this Org vDC.
#
# @param [String] vdc_id Object identifier of the VDC
# @return [Excon::Response]
# * body<~Hash>:
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-OrgVdcGateways.html
# vCloud API Documentation
# @since vCloud API version 5.1
def get_edge_gateways(vdc_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "admin/vdc/#{vdc_id}/edgeGateways"
)
end
end
class Mock
def get_edge_gateways(vdc_id)
response = Excon::Response.new
unless valid_uuid?(vdc_id)
response.status = 400
raise Excon::Errors.status_error({:expects => 200}, response)
end
unless vdc = data[:vdcs][vdc_id]
response.status = 403
raise Excon::Errors.status_error({:expects => 200}, response)
end
body =
{:xmlns => xmlns,
:xmlns_xsi => xmlns_xsi,
:total => "1",
:pageSize => "25",
:page => "1",
:name => "edgeGateways",
:type => "application/vnd.vmware.vcloud.query.records+xml",
:href => make_href("admin/vdc/#{vdc_id}edgeGateways?page=1&pageSize=25&format=records"),
:xsi_schemaLocation => xsi_schema_location,
:Link =>
[{:rel => "alternate",
:type => "application/vnd.vmware.vcloud.query.references+xml",
:href => make_href("admin/vdc/#{vdc_id}edgeGateways?page=1&pageSize=25&format=references")},
{:rel => "alternate",
:type => "application/vnd.vmware.vcloud.query.idrecords+xml",
:href => make_href("admin/vdc/#{vdc_id}edgeGateways?page=1&pageSize=25&format=records")}],
:EdgeGatewayRecord => []}
vdc_edge_gateways = data[:edge_gateways].select do |id, edge_gateway|
edge_gateway[:vdc] == vdc_id
end
body[:EdgeGatewayRecord] += vdc_edge_gateways.map do |id, edge_gateway|
{:vdc => make_href("vdc/#{vdc_id}"),
:numberOfOrgNetworks => "1",
:numberOfExtNetworks => "1",
:name => edge_gateway[:name],
:isBusy => "false",
:haStatus => "DISABLED",
:gatewayStatus => "READY",
:href => make_href("admin/edgeGateway/#{id}"),
:isSyslogServerSettingInSync => "true"}
end
response.status = 200
response.headers = {'Content-Type' => "#{body[:type]};version=#{api_version}"}
response.body = body
response
end
end
end
end
end

View file

@ -0,0 +1,48 @@
Shindo.tests('Compute::VcloudDirector | edge gateway requests', ['vclouddirector']) do
@service = Fog::Compute::VcloudDirector.new
tests('Get current organization') do
session = @service.get_current_session.body
link = session[:Link].detect do |l|
l[:type] == 'application/vnd.vmware.vcloud.org+xml'
end
@org = @service.get_organization(link[:href].split('/').last).body
end
tests('Get first vdc') do
link = @org[:Link].detect do |l|
l[:type] == 'application/vnd.vmware.vcloud.vdc+xml'
end
@vdc_id = link[:href].split('/').last
end
tests('#get_edge_gateways').data_matches_schema(VcloudDirector::Compute::Schema::QUERY_RESULT_RECORDS_TYPE) do
@edge_gateways = @service.get_edge_gateways(@vdc_id).body
# ensure that EdgeGatewayRecord is a list
if @edge_gateways[:EdgeGatewayRecord].is_a?(Hash)
@edge_gateways[:EdgeGatewayRecord] = [@edge_gateways[:EdgeGatewayRecord]]
end
@edge_gateways[:EdgeGatewayRecord].each do |result|
tests("each EdgeGatewayRecord should follow schema").
data_matches_schema(VcloudDirector::Compute::Schema::QUERY_RESULT_EDGE_GATEWAY_RECORD_TYPE) { result }
end
@edge_gateways
end
tests('#get_edge_gateway').data_matches_schema(VcloudDirector::Compute::Schema::GATEWAY_TYPE) do
@service.get_edge_gateway(@edge_gateways[:EdgeGatewayRecord].first[:href].split('/').last).body
end
tests('Retrieve non-existent edge gateway').raises(Excon::Errors::Forbidden) do
@service.get_edge_gateway('00000000-0000-0000-0000-000000000000')
end
tests('Retrieve edge gateways for non-existent VDC').raises(Excon::Errors::Forbidden) do
@service.get_edge_gateways('00000000-0000-0000-0000-000000000000')
end
end

View file

@ -289,6 +289,243 @@ class VcloudDirector
:OperatingSystemFamilyInfo => [OPERATING_SYSTEM_FAMILY_INFO_TYPE]
})
# Container for query results in records format.
# Combine with QUERY_RESULT_RECORD_TYPE subtypes to validate query results
QUERY_RESULT_RECORDS_TYPE = {
:href => Fog::Nullable::String,
:type => Fog::Nullable::String,
:name => Fog::Nullable::String,
:page => Fog::Nullable::String,
:pageSize => Fog::Nullable::String,
:total => Fog::Nullable::String,
}
# Base type for a single record from query result in records format.
# Subtypes define more specific elements.
QUERY_RESULT_RECORD_TYPE = {
:href => String,
:id => Fog::Nullable::String,
:type => Fog::Nullable::String
}
# Type for a single edgeGateway query result in records format.
QUERY_RESULT_EDGE_GATEWAY_RECORD_TYPE = QUERY_RESULT_RECORD_TYPE.merge({
:gatewayStatus => String,
:haStatus => String,
:isBusy => String,
:name => String,
:numberOfExtNetworks => String,
:numberOfOrgNetworks=> String,
:vdc => String
})
FIREWALL_RULE_TYPE__PROTOCOLS = {
:Icmp => Fog::Nullable::String,
:Asny => Fog::Nullable::String,
:Other => Fog::Nullable::String
}
# Represents a firewall rule.
FIREWALL_RULE_TYPE = {
:Id => String,
:IsEnabled => String,
:MatchOnTranslate => Fog::Nullable::String,
:Description => Fog::Nullable::String,
:Policy => Fog::Nullable::String,
:IcmpSubType => Fog::Nullable::String,
:Port => Fog::Nullable::String,
:DestinationPortRange => String,
:SourcePort => Fog::Nullable::String,
:SourcePortRange => String,
:Direction => Fog::Nullable::String,
:EnableLogging => Fog::Nullable::String,
:Protocols => FIREWALL_RULE_TYPE__PROTOCOLS
}
# Represents a network firewall service.
FIREWALL_SERVICE_TYPE = {
:IsEnabled => String,
:DefaultAction => String,
:LogDefaultAction => String,
#:FirewallRule => [FIREWALL_RULE_TYPE] # not required
}
#Represents the SNAT and DNAT rules.
GATEWAY_NAT_RULE_TYPE = {
:Interface => REFERENCE_TYPE,
:OriginalIp => String,
:OriginalPort => Fog::Nullable::String,
:TranslatedIp => String,
:TranslatedPort => Fog::Nullable::String,
:Protocol => Fog::Nullable::String,
:IcmpSubType => Fog::Nullable::String
}
#Represents a NAT rule.
NAT_RULE_TYPE = {
:Description => Fog::Nullable::String,
:RuleType => String,
:IsEnabled => String,
:Id => String,
:GatewayNatRule => GATEWAY_NAT_RULE_TYPE
}
# Represents a NAT network service.
NAT_SERVICE_TYPE = {
:IsEnabled => String,
:NatType => Fog::Nullable::String,
:Policy => Fog::Nullable::String,
#:NatRule => [NAT_RULE_TYPE], # not required
:ExternalIp => Fog::Nullable::String
}
# Represents a service port in a load balancer pool.
LB_POOL_SERVICE_PORT_TYPE = {
:IsEnabled => Fog::Nullable::String,
:Protocol => String,
:Algorithm => Fog::Nullable::String,
:Port => String,
:HealthCheckPort => String,
#:HealthCheck => LBPoolHealthCheckType # not required
}
# Represents a member in a load balancer pool.
LB_POOL_MEMBER_TYPE = {
:IpAddress => String,
:Weight => String,
:ServicePort => [LB_POOL_SERVICE_PORT_TYPE]
}
# Represents a load balancer pool.
LOAD_BALANCER_POOL_TYPE = {
:Id => Fog::Nullable::String,
:Name => String,
:Description => Fog::Nullable::String,
:ServicePort => [LB_POOL_SERVICE_PORT_TYPE],
:Member => [LB_POOL_MEMBER_TYPE],
:Operational => String,
:ErrorDetails => Fog::Nullable::String
}
# Represents persistence type for a load balancer service profile.
LB_PERSISTENCE_TYPE = {
:Method => String,
:CookieName => Fog::Nullable::String,
:CookieMode => Fog::Nullable::String
}
# Represents service profile for a load balancing virtual server.
LB_VIRTUAL_SERVER_SERVICE_PROFILE_TYPE = {
:IsEnabled => String,
:Protocol => String,
:Port => String,
:Persistence => LB_PERSISTENCE_TYPE
}
# Information about a vendor service template. This is optional.
VENDOR_TEMPLATE_TYPE = {
:Name => String,
:Id => String
}
# Represents a load balancer virtual server.
LOAD_BALANCER_VIRTUAL_SERVER_TYPE = {
:IsEnabled => String,
:Name => String,
:Description => Fog::Nullable::String,
:Interface => REFERENCE_TYPE,
:IpAddress => String,
:ServiceProfile => [LB_VIRTUAL_SERVER_SERVICE_PROFILE_TYPE],
:Logging => String,
:Pool => String,
#:LoadBalancerTemplates => VENDOR_TEMPLATE_TYPE # not required
}
# Represents gateway load balancer service.
LOAD_BALANCER_SERVICE_TYPE = {
:Pool => LOAD_BALANCER_POOL_TYPE,
:VirtualServer => LOAD_BALANCER_VIRTUAL_SERVER_TYPE,
:IsEnabled => Fog::Nullable::String
}
# Represents Gateway DHCP service.
GATEWAY_DHCP_SERVICE_TYPE = {
:IsEnabled => String,
#:Pool => DHCP_POOL_SERVICE_TYPE # not required
}
# Represents edge gateway services.
GATEWAY_FEATURES_TYPE = {
#:StaticRoutingService => STATIC_ROUTING_SERVICE_TYPE, #not required
#:GatewayIpsecVpnService => GATEWAY_IPSEC_VPN_SERVICE_TYPE, #not required
#:GatewayDhcpService => GATEWAY_DHCP_SERVICE_TYPE, #not required
#:LoadBalancerService => LOAD_BALANCER_SERVICE_TYPE, #not required
:NatService => NAT_SERVICE_TYPE,
:FirewallService => FIREWALL_SERVICE_TYPE
}
# Represents a range of IP addresses, start and end inclusive.
IP_RANGE_TYPE = {
:StartAddress => String,
:EndAddress => String
}
# Represents a list of IP ranges.
IP_RANGES_TYPE = {
:IpRange => [IP_RANGE_TYPE]
}
# Allows to chose which subnets a gateway can be part of
SUBNET_PARTICIPATION_TYPE = {
:Gateway => String,
:Netmask => String,
:IpAddress => String,
:IpRanges => IP_RANGES_TYPE
}
# Gateway Interface configuration.
GATEWAY_INTERFACE_TYPE = {
:Name => String,
:DisplayName => String,
:Network => REFERENCE_TYPE,
:InterfaceType => String,
#:SubnetParticipation => [SUBNET_PARTICIPATION_TYPE], #bug in parser means list or hash
:ApplyRateLimit => String,
:InRateLimit => Fog::Nullable::String,
:OutRateLimit => Fog::Nullable::String,
:UseForDefaultRoute => String,
}
# A list of Gateway Interfaces.
GATEWAY_INTERFACES_TYPE = {
:GatewayInterface => [GATEWAY_INTERFACE_TYPE]
}
# Gateway Configuration.
GATEWAY_CONFIGURATION_TYPE = {
:BackwardCompatibilityMode => Fog::Nullable::String,
:GatewayBackingConfig => String,
:GatewayInterfaces => GATEWAY_INTERFACES_TYPE,
:EdgeGatewayServiceConfiguration => GATEWAY_FEATURES_TYPE,
:HaEnabled => Fog::Nullable::String,
:UseDefaultRouteForDnsRelay => Fog::Nullable::String
}
# Represents a gateway.
GATEWAY_TYPE = {
:href => String,
:type => String,
:id => String,
:operationKey => Fog::Nullable::String,
:name => String,
:status => Fog::Nullable::String,
#:Link => LINK_TYPE, # not required
:Description => Fog::Nullable::String,
#:Tasks => TASKS_IN_PROGRESS_TYPE, # not required
:Configuration => GATEWAY_CONFIGURATION_TYPE
}
end
end
end