Module: OneviewSDK::API300::C7000::Scope::ScopeHelperMethods

Included in:
Enclosure, LogicalSwitch, OneviewSDK::API300::C7000::ServerHardware, OneviewSDK::API300::C7000::Switch
Defined in:
lib/oneview-sdk/resource/api300/c7000/scope.rb

Overview

Helper methods for add, remove and replace scopes from the another resources

Instance Method Summary collapse

Instance Method Details

#add_scope(scope) ⇒ Object

Add one scope to the resource

Parameters:

Raises:


114
115
116
117
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 114

def add_scope(scope)
  scope.ensure_uri
  patch('add', '/scopeUris/-', scope['uri'])
end

#patch(operation, path, value = nil) ⇒ Object

Note:

This attribute is subject to incompatible changes in future release versions, including redefinition or removal.

Performs a specific patch operation for the given server. If the server supports the particular operation, the operation is performed and a response is returned to the caller with the results.

Parameters:

  • operation (String)

    The operation to be performed

  • path (String)

    The path of operation

  • value (String) (defaults to: nil)

    The value


100
101
102
103
104
105
106
107
108
109
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 100

def patch(operation, path, value = nil)
  ensure_client && ensure_uri
  body = {
    'op' => operation,
    'path' => path,
    'value' => value
  }
  response = @client.rest_patch(@data['uri'], { 'body' => [body] }, @api_version)
  @client.response_handler(response)
end

#remove_scope(scope) ⇒ Boolean

Remove one scope from the resource

Parameters:

Returns:

  • (Boolean)

    True if the scope was deleted and false if enclosure has not the scope

Raises:


123
124
125
126
127
128
129
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 123

def remove_scope(scope)
  scope.ensure_uri
  scope_index = @data['scopeUris'].find_index { |uri| uri == scope['uri'] }
  return false unless scope_index
  patch('remove', "/scopeUris/#{scope_index}", nil)
  true
end

#replace_scopes(*scopes) ⇒ Object

Change the list of scopes in the resource

Parameters:

Raises:


134
135
136
137
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 134

def replace_scopes(*scopes)
  uris = ensure_and_get_uris(scopes.flatten)
  patch('replace', '/scopeUris', uris)
end