Class: OneviewSDK::API200::LogicalSwitch

Inherits:
Resource show all
Defined in:
lib/oneview-sdk/resource/api200/logical_switch.rb

Overview

Logical switch resource implementation

Defined Under Namespace

Classes: CredentialsSNMPV1, CredentialsSNMPV3, CredentialsSSH

Constant Summary collapse

BASE_URI =
'/rest/logical-switches'.freeze

Constants inherited from Resource

Resource::DEFAULT_REQUEST_HEADER, Resource::UNIQUE_IDENTIFIERS

Instance Attribute Summary collapse

Attributes inherited from Resource

#api_version, #client, #data, #logger

Credentials collapse

Instance Method Summary collapse

Methods inherited from Resource

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

Constructor Details

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

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.



26
27
28
29
30
31
# File 'lib/oneview-sdk/resource/api200/logical_switch.rb', line 26

def initialize(client, params = {}, api_ver = nil)
  super
  # Default values
  @data['type'] ||= 'logical-switch'
  @logical_switch_credentials = {}
end

Instance Attribute Details

#logical_switch_credentialsObject

Returns the value of attribute logical_switch_credentials.



20
21
22
# File 'lib/oneview-sdk/resource/api200/logical_switch.rb', line 20

def logical_switch_credentials
  @logical_switch_credentials
end

Instance Method Details

#create(header = {}) ⇒ OneviewSDK::LogicalSwitch

Create method

Parameters:

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

    The header options for the request (key-value pairs)

Returns:

  • (OneviewSDK::LogicalSwitch)

    self

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/oneview-sdk/resource/api200/logical_switch.rb', line 38

def create(header = {})
  ensure_client
  request_body = {}
  request_body['logicalSwitchCredentials'] = generate_logical_switch_credentials
  request_body['logicalSwitch'] = @data.clone
  request_body['logicalSwitch']['switchCredentialConfiguration'] = generate_logical_switch_credential_configuration
  options = DEFAULT_REQUEST_HEADER.merge(header).merge('body' => request_body)
  response = @client.rest_post(self.class::BASE_URI, options, @api_version)
  body = @client.response_handler(response)
  set_all(body)
  self
end

#refresh_stateObject

Reclaims the top-of-rack switches in a logical switch.



52
53
54
55
# File 'lib/oneview-sdk/resource/api200/logical_switch.rb', line 52

def refresh_state
  response = @client.rest_put(@data['uri'] + '/refresh')
  @client.response_handler(response)
end

#set_logical_switch_group(logical_switch_group) ⇒ Object

Sets the logical switch group

Parameters:

  • logical_switch_group (OneviewSDK::logicalSwitchGroup)

    Logical switch group



94
95
96
# File 'lib/oneview-sdk/resource/api200/logical_switch.rb', line 94

def set_logical_switch_group(logical_switch_group)
  @data['logicalSwitchGroupUri'] = logical_switch_group['uri']
end

#set_switch_credentials(host, ssh_credentials, snmp_credentials) ⇒ Array

Sets switch credentials

Parameters:

  • host (String)

    IP address or host name

  • ssh_credentials (CredentialsSSH)

    SSH credentials

  • snmp_credentials (CredentialsSNMP)

    SNMP credentials

Returns:

  • (Array)

    An Array containing the SSH and SNMP credentials

Raises:

  • (TypeError)


80
81
82
83
84
85
86
87
# File 'lib/oneview-sdk/resource/api200/logical_switch.rb', line 80

def set_switch_credentials(host, ssh_credentials, snmp_credentials)
  raise TypeError, 'Use struct<OneviewSDK::LogicalSwitch::CredentialsSSH>' if ssh_credentials.class != OneviewSDK::LogicalSwitch::CredentialsSSH
  raise TypeError, 'Use struct<OneviewSDK::LogicalSwitch::CredentialsSNMP>' unless snmp_credentials.respond_to?('version')
  raise TypeError, 'Use struct<OneviewSDK::LogicalSwitch::CredentialsSNMP>' if snmp_credentials.version != 'SNMPv1' &&
    snmp_credentials.version != 'SNMPv3'
  @logical_switch_credentials[host] = [ssh_credentials.clone, snmp_credentials.clone]
  @logical_switch_credentials[host]
end