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

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:



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

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



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

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:



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

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:



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

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