class OneviewSDK::API600::C7000::Scope

Scope resource implementation for API600 C7000

Public Class Methods

add_resource_scope(client, resource, scopes: []) click to toggle source

Add a scope to resource's scope list @param [OneviewSDK::Client] client The client object for the OneView appliance @param [OneviewSDK::API600::C7000::Resource] resource Any resource object @param [Array] scopes The array of scopes (or any number of scopes separated by comma)

# File lib/oneview-sdk/resource/api600/c7000/scope.rb, line 89
def self.add_resource_scope(client, resource, scopes: [])
  resource_patch(client, resource, add_scopes: scopes)
end
get_resource_scopes(client, resource) click to toggle source

Gets a resource's scope, containing a list of the scopes to which the resource is assigned. @param [OneviewSDK::Client] client The client object for the OneView appliance @param [OneviewSDK::API600::C7000::Resource] resource Resource object

# File lib/oneview-sdk/resource/api600/c7000/scope.rb, line 35
def self.get_resource_scopes(client, resource)
  scopes_uri = resource['scopesUri']
  response = client.rest_get(scopes_uri)
  client.response_handler(response)
end
new(client, params = {}, api_ver = nil) click to toggle source

Create a resource object, associate it with a client, and set its properties. @param [OneviewSDK::Client] client The client object for the OneView appliance @param [Hash] params The options for this resource (key-value pairs) @param [Integer] api_ver The api version to use when interracting with this resource.

Calls superclass method OneviewSDK::API500::C7000::Scope::new
# File lib/oneview-sdk/resource/api600/c7000/scope.rb, line 24
def initialize(client, params = {}, api_ver = nil)
  @data ||= {}
  # Default values:
  @data['type'] ||= 'ScopeV3'
  super
end
remove_resource_scope(client, resource, scopes: []) click to toggle source

Remove a scope from resource's scope list. @param [OneviewSDK::Client] client The client object for the OneView appliance @param [OneviewSDK::API600::C7000::Resource] resource Any resource object @param [Array] scopes The array of scopes (or any number of scopes separated by comma)

# File lib/oneview-sdk/resource/api600/c7000/scope.rb, line 97
def self.remove_resource_scope(client, resource, scopes: [])
  resource_patch(client, resource, remove_scopes: scopes)
end
replace_resource_assigned_scopes(client, resource, scopes: []) click to toggle source

Replaces a resource's assigned scopes using the specified list of scope URIs. @param [OneviewSDK::Client] client The client object for the OneView appliance @param [OneviewSDK::API600::C7000::Resource] resource Resource object @param [Array<OneviewSDK::API600::C7000::Scope>] scopes Array of scopes objects

# File lib/oneview-sdk/resource/api600/c7000/scope.rb, line 45
def self.replace_resource_assigned_scopes(client, resource, scopes: [])
  resource_uri = resource['uri']
  scope_uris = scopes.map { |scope| scope['uri'] }
  scopes_uri = resource['scopesUri']
  options = { 'Content-Type' => 'application/json-patch+json',
              'If-Match' => '*',
              'body' => { 'type' => 'ScopedResource',
                          'resourceUri' => resource_uri,
                          'scopeUris' => scope_uris } }
  response = client.rest_put(scopes_uri, options)
  client.response_handler(response)
end
resource_patch(client, resource, add_scopes: [], remove_scopes: []) click to toggle source

Performs a specific patch operation. @param [OneviewSDK::Client] client The client object for the OneView appliance @param [OneviewSDK::API600::C7000::Resource] resource Any resource object @param [Array<OneviewSDK::API600::C7000::Scope>] scopes Array of scopes objects

# File lib/oneview-sdk/resource/api600/c7000/scope.rb, line 62
def self.resource_patch(client, resource, add_scopes: [], remove_scopes: [])
  scopes_body = []
  scopes_uri = resource['scopesUri']
  unless add_scopes.empty?
    add_scopes.each do |scope|
      add_body = { 'op' => 'add', 'path' => '/scopeUris/-', 'value' => scope['uri'] }
      scopes_body.push(add_body)
    end
  end
  unless remove_scopes.empty?
    remove_scopes.each do |scope|
      scope_uris = get_resource_scopes(client, resource)['scopeUris']
      scope_index = scope_uris.find_index { |uri| uri == scope['uri'] }
      remove_body = { 'op' => 'remove', 'path' => "/scopeUris/#{scope_index}" }
      scopes_body.push(remove_body)
    end
  end
  options = { 'Content-Type' => 'application/json-patch+json',
              'If-Match' => '*', 'body' => scopes_body }
  response = client.rest_patch(scopes_uri, options, client.api_version)
  client.response_handler(response)
end