Class: OneviewSDK::API600::C7000::Scope

Inherits:
OneviewSDK::API500::C7000::Scope show all
Defined in:
lib/oneview-sdk/resource/api600/c7000/scope.rb

Overview

Scope resource implementation for API600 C7000

Constant Summary

Constants inherited from OneviewSDK::API300::C7000::Scope

OneviewSDK::API300::C7000::Scope::BASE_URI

Constants inherited from Resource

Resource::BASE_URI, Resource::DEFAULT_REQUEST_HEADER, Resource::UNIQUE_IDENTIFIERS

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OneviewSDK::API500::C7000::Scope

#change_resource_assignments, #patch

Methods inherited from OneviewSDK::API300::C7000::Scope

#change_resource_assignments, #delete, #set_resources, #unset_resources, #update

Methods inherited from Resource

#==, #[], #[]=, build_query, #create, #create!, #deep_merge!, #delete, #each, #eql?, #exists?, find_by, find_with_pagination, from_file, get_all, get_all_with_query, #like?, #refresh, #retrieve!, #schema, schema, #set, #set_all, #to_file, #update

Constructor Details

#initialize(client, params = {}, api_ver = nil) ⇒ Scope

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.



24
25
26
27
28
29
# 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

Class Method Details

.add_resource_scope(client, resource, scopes: []) ⇒ Object

Add a scope to resource’s scope list

Parameters:



89
90
91
# 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) ⇒ Object

Gets a resource’s scope, containing a list of the scopes to which the resource is assigned.

Parameters:



35
36
37
38
39
# 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

.remove_resource_scope(client, resource, scopes: []) ⇒ Object

Remove a scope from resource’s scope list.

Parameters:



97
98
99
# 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: []) ⇒ Object

Replaces a resource’s assigned scopes using the specified list of scope URIs.

Parameters:



45
46
47
48
49
50
51
52
53
54
55
56
# 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: []) ⇒ Object

Performs a specific patch operation.

Parameters:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 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