Class: OneviewSDK::LogicalInterconnectGroup

Inherits:
Resource
  • Object
show all
Defined in:
lib/oneview-sdk/resource/logical_interconnect_group.rb

Overview

Logical interconnect group resource implementation

Constant Summary collapse

BASE_URI =
'/rest/logical-interconnect-groups'.freeze

Instance Attribute Summary collapse

Attributes inherited from Resource

#api_version, #client, #data, #logger

Instance Method Summary collapse

Methods inherited from Resource

#==, #[], #[]=, build_query, #create, #create!, #delete, #each, #eql?, #exists?, find_by, from_file, get_all, #like?, #refresh, #retrieve!, #schema, schema, #set, #set_all, #to_file

Constructor Details

#initialize(client, params = {}, api_ver = nil) ⇒ LogicalInterconnectGroup

Create a resource object, associate it with a client, and set its properties.

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • params (Hash) (defaults to: {})

    The options for this resource (key-value pairs)

  • api_ver (Integer) (defaults to: nil)

    The api version to use when interracting with this resource.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/oneview-sdk/resource/logical_interconnect_group.rb', line 23

def initialize(client, params = {}, api_ver = nil)
  super
  # Default values:
  @data['enclosureType'] ||= 'C7000'
  @data['state'] ||= 'Active'
  @data['uplinkSets'] ||= []
  @data['type'] ||= 'logical-interconnect-groupV3'
  @data['interconnectMapTemplate'] ||= {}
  @data['interconnectMapTemplate']['interconnectMapEntryTemplates'] ||= []

  # User friendly values:
  @bay_count = 8

  # Create all entries if empty
  parse_interconnect_map_template if @data['interconnectMapTemplate']['interconnectMapEntryTemplates'] == []
end

Instance Attribute Details

#bay_countObject (readonly)

Returns the value of attribute bay_count.



17
18
19
# File 'lib/oneview-sdk/resource/logical_interconnect_group.rb', line 17

def bay_count
  @bay_count
end

Instance Method Details

#add_interconnect(bay, type) ⇒ Object

Adds an interconnect

Parameters:

  • bay (Fixnum)

    Bay number

  • type (String)

    Interconnect type

Raises:

  • (StandardError)

    if a invalid type is given then raises an error



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/oneview-sdk/resource/logical_interconnect_group.rb', line 44

def add_interconnect(bay, type)
  @data['interconnectMapTemplate']['interconnectMapEntryTemplates'].each do |entry|
    entry['logicalLocation']['locationEntries'].each do |location|
      if location['type'] == 'Bay' && location['relativeValue'] == bay
        entry['permittedInterconnectTypeUri'] = OneviewSDK::Interconnect.get_type(@client, type)['uri']
      end
    end
  end
rescue StandardError
  list = OneviewSDK::Interconnect.get_types(@client).map { |t| t['name'] }
  raise "Interconnect type #{type} not found! Supported types: #{list}"
end

Adds an uplink set

Parameters:



59
60
61
# File 'lib/oneview-sdk/resource/logical_interconnect_group.rb', line 59

def add_uplink_set(uplink_set)
  @data['uplinkSets'] << uplink_set.data
end

#get_default_settingsHash

Get the logical interconnect group default settings

Returns:

  • (Hash)

    The logical interconnect group settings



65
66
67
68
69
# File 'lib/oneview-sdk/resource/logical_interconnect_group.rb', line 65

def get_default_settings
  get_uri = self.class::BASE_URI + '/defaultSettings'
  response = @client.rest_get(get_uri, @api_version)
  @client.response_handler(response)
end

#get_settingsHash

Gets the logical interconnect group settings

Returns:

  • (Hash)

    The logical interconnect group settings



73
74
75
76
77
# File 'lib/oneview-sdk/resource/logical_interconnect_group.rb', line 73

def get_settings
  get_uri = @data['uri'] + '/settings'
  response = @client.rest_get(get_uri, @api_version)
  @client.response_handler(response)
end

#update(attributes = {}) ⇒ Object

Saves the current data attributes to the Logical Interconnect Group

Parameters:

  • attributes (Hash) (defaults to: {})

    attributes to be updated

Returns:

  • Updated instance of the Logical Interconnect Group



82
83
84
85
86
87
88
89
90
91
# File 'lib/oneview-sdk/resource/logical_interconnect_group.rb', line 82

def update(attributes = {})
  set_all(attributes)
  update_options = {
    'If-Match' =>  @data.delete('eTag'),
    'Body' => @data
  }
  response = @client.rest_put(@data['uri'], update_options, @api_version)
  body = @client.response_handler(response)
  set_all(body)
end