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

Direct Known Subclasses

Synergy::Scope

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

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

Instance Method Details

#add_resource_scope(resource, scope) ⇒ Object

Add a scope to resource’s scope list

Parameters:



75
76
77
78
# File 'lib/oneview-sdk/resource/api600/c7000/scope.rb', line 75

def add_resource_scope(resource, scope)
  scopes_uri = resource['scopesUri']
  resource_patch(scopes_uri, 'add', '/scopeUris/-', scope['uri'])
end

#get_resource_scopes(resource) ⇒ Object

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

Parameters:



34
35
36
37
38
# File 'lib/oneview-sdk/resource/api600/c7000/scope.rb', line 34

def get_resource_scopes(resource)
  scopes_uri = resource['scopesUri']
  response = @client.rest_get(scopes_uri)
  @client.response_handler(response)
end

#remove_resource_scope(resource, scope) ⇒ Object

Remove a scope from resource’s scope list.

Parameters:



83
84
85
86
87
88
# File 'lib/oneview-sdk/resource/api600/c7000/scope.rb', line 83

def remove_resource_scope(resource, scope)
  scope_uris = get_resource_scopes(resource)['scopeUris']
  scope_index = scope_uris.find_index { |uri| uri == scope['uri'] }
  resource_uri = resource['scopesUri']
  resource_patch(resource_uri, 'remove', "/scopeUris/#{scope_index}", nil)
end

#replace_resource_assigned_scopes(resource, scopes: []) ⇒ Object

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

Parameters:



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/oneview-sdk/resource/api600/c7000/scope.rb', line 43

def replace_resource_assigned_scopes(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(scopes_uri, operation, path, value = nil) ⇒ Object

Performs a specific patch operation.

Parameters:

  • scopes_uri (String)

    resource’s scopes uri

  • operation (String)

    The operation to be performed

  • path (String)

    The path of operation

  • value (String) (defaults to: nil)

    The value



61
62
63
64
65
66
67
68
69
70
# File 'lib/oneview-sdk/resource/api600/c7000/scope.rb', line 61

def resource_patch(scopes_uri, operation, path, value = nil)
  ensure_client && ensure_uri
  body = { 'op' => operation,
           'path' => path,
           'value' => value }
  options = { 'Content-Type' => 'application/json-patch+json',
              'If-Match' => '*', 'body' => [body] }
  response = @client.rest_patch(scopes_uri, options, @api_version)
  @client.response_handler(response)
end