Class: Vcloud::Core::EdgeGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/vcloud/core/edge_gateway.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Vcloud::Core::EdgeGateway

Initialize a new EdgeGateway and check that the provided ID is in the correct format (lowercase string containing hexadecimal characters or hyphens)

Parameters:

  • id (String)

    The ID of gateway



13
14
15
16
17
18
# File 'lib/vcloud/core/edge_gateway.rb', line 13

def initialize(id)
  unless id =~ /^[-0-9a-f]+$/
    raise "EdgeGateway id : #{id} is not in correct format"
  end
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/vcloud/core/edge_gateway.rb', line 5

def id
  @id
end

Class Method Details

.get_by_name(name) ⇒ Vcloud::Core::EdgeGateway

Return the EdgeGateway instance that is the first match for the supplied name.

Parameters:

  • name (String)

    The name of the EdgeGateway

Returns:



61
62
63
64
65
66
# File 'lib/vcloud/core/edge_gateway.rb', line 61

def self.get_by_name(name)
  ids = self.get_ids_by_name(name)
  raise "edgeGateway #{name} not found" if ids.size == 0
  raise "edgeGateway #{name} is not unique" if ids.size > 1
  return self.new(ids.first)
end

.get_ids_by_name(name) ⇒ Array

Find a list of EdgeGateway IDs that match a name

Parameters:

  • name (String)

    The name of the EdgeGateway

Returns:

  • (Array)

    An array of IDs found.



24
25
26
27
28
29
30
31
# File 'lib/vcloud/core/edge_gateway.rb', line 24

def self.get_ids_by_name(name)
  q = Vcloud::Core::QueryRunner.new
  query_results = q.run('edgeGateway', :filter => "name==#{name}")
  raise "Error finding edgeGateway by name #{name}" unless query_results
  query_results.collect do |record|
    record[:href].split('/').last if record.key?(:href)
  end
end

Instance Method Details

#hrefString

Return the href of EdgeGateway

Returns:

  • (String)

    href of EdgeGateway



79
80
81
# File 'lib/vcloud/core/edge_gateway.rb', line 79

def href
  vcloud_attributes[:href]
end

#interfacesArray

For each GatewayInterfaces item in the configuration, create an EdgeGatewayInterface object to allow decisions based on the connected networks to be taken without inspecting the API details.

Returns:

  • (Array)

    An array of Vcloud::Core::EdgeGatewayInterface objects



95
96
97
98
99
100
101
102
103
# File 'lib/vcloud/core/edge_gateway.rb', line 95

def interfaces
  gateway_config = vcloud_attributes[:Configuration]
  return [] unless gateway_config[:GatewayInterfaces]
  gateway_interfaces = gateway_config[:GatewayInterfaces][:GatewayInterface]
  return [] unless gateway_interfaces
  gateway_interfaces.map do |vcloud_gateway_interface_hash|
    EdgeGatewayInterface.new(vcloud_gateway_interface_hash)
  end
end

#nameString

Return the name of EdgeGateway

Returns:

  • (String)

    name of EdgeGateway



86
87
88
# File 'lib/vcloud/core/edge_gateway.rb', line 86

def name
  vcloud_attributes[:name]
end

#update_configuration(config) ⇒ Object

Update configuration for EdgeGateway

Parameters:

  • config (Hash)

    A configuration for EdgeGateway



37
38
39
40
# File 'lib/vcloud/core/edge_gateway.rb', line 37

def update_configuration(config)
  fsi = Vcloud::Core::Fog::ServiceInterface.new
  fsi.post_configure_edge_gateway_services(id, config)
end

#vcloud_attributesString

Get the vCloud attributes for EdgeGateway

Returns:

  • (String)

    Excon::Response#body from vCloud for EdgeGateway



71
72
73
74
# File 'lib/vcloud/core/edge_gateway.rb', line 71

def vcloud_attributes
  fsi = Vcloud::Core::Fog::ServiceInterface.new
  fsi.get_edge_gateway(id)
end

#vcloud_gateway_interface_by_id(gateway_interface_id) ⇒ Vcloud::Core::EdgeGatewayInterface

Return the Vcloud::Core::EdgeGatewayInterface of EdgeGateway which matches an ID

Parameters:

  • id (String)

    The id of the EdgeGatewayInterface

Returns:



47
48
49
50
51
52
53
54
# File 'lib/vcloud/core/edge_gateway.rb', line 47

def vcloud_gateway_interface_by_id gateway_interface_id
  gateway_interfaces = vcloud_attributes[:Configuration][:GatewayInterfaces][:GatewayInterface]
  unless gateway_interfaces.empty?
    return gateway_interfaces.find{ |interface|
      interface[:Network][:href].split('/').last == gateway_interface_id
    }
  end
end