Class: OneviewSDK::LogicalSwitch

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

Overview

Logical switch resource implementation

Defined Under Namespace

Classes: CredentialsSNMPV1, CredentialsSNMPV3, CredentialsSSH

Constant Summary collapse

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

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?, #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.



23
24
25
26
27
28
# File 'lib/oneview-sdk/resource/logical_switch.rb', line 23

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.



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

def logical_switch_credentials
  @logical_switch_credentials
end

Instance Method Details

#createOneviewSDK::LogicalSwitch

Create method

Returns:

Raises:



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/oneview-sdk/resource/logical_switch.rb', line 34

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

#refreshResource

Note:

Will overwrite any data that differs from OneView

Updates this object using the data that exists on OneView

Returns:



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

def refresh
  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



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

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



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

def set_switch_credentials(host, ssh_credentials, snmp_credentials)
  fail TypeError, 'Use struct<OneviewSDK::LogicalSwitch::CredentialsSSH>' if ssh_credentials.class != OneviewSDK::LogicalSwitch::CredentialsSSH
  fail TypeError, 'Use struct<OneviewSDK::LogicalSwitch::CredentialsSNMP>' unless snmp_credentials.respond_to?('version')
  fail 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