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::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!, #delete, #each, #eql?, #exists?, find_by, from_file, get_all, #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

#createOneviewSDK::LogicalSwitch

Create method

Returns:

  • (OneviewSDK::LogicalSwitch)

    self

Raises:


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

def create
  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
  response = @client.rest_post(self.class::BASE_URI, { 'body' => request_body }, @api_version)
  body = @client.response_handler(response)
  set_all(body)
  self
end

#refresh_stateObject

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


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

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


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

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)

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

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