Class: OneviewSDK::API600::C7000::Scope
- Inherits:
-
OneviewSDK::API500::C7000::Scope
- Object
- Resource
- OneviewSDK::API300::C7000::Scope
- OneviewSDK::API500::C7000::Scope
- OneviewSDK::API600::C7000::Scope
- Defined in:
- lib/oneview-sdk/resource/api600/c7000/scope.rb
Overview
Scope resource implementation for API600 C7000
Direct Known Subclasses
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
-
.add_resource_scope(client, resource, scopes: []) ⇒ Object
Add a scope to resource’s scope list.
-
.get_resource_scopes(client, resource) ⇒ Object
Gets a resource’s scope, containing a list of the scopes to which the resource is assigned.
-
.remove_resource_scope(client, resource, scopes: []) ⇒ Object
Remove a scope from resource’s scope list.
-
.replace_resource_assigned_scopes(client, resource, scopes: []) ⇒ Object
Replaces a resource’s assigned scopes using the specified list of scope URIs.
-
.resource_patch(client, resource, add_scopes: [], remove_scopes: []) ⇒ Object
Performs a specific patch operation.
Instance Method Summary collapse
-
#initialize(client, params = {}, api_ver = nil) ⇒ Scope
constructor
Create a resource object, associate it with a client, and set its properties.
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.
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
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.
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.
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.
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'] = { 'Content-Type' => 'application/json-patch+json', 'If-Match' => '*', 'body' => { 'type' => 'ScopedResource', 'resourceUri' => resource_uri, 'scopeUris' => scope_uris } } response = client.rest_put(scopes_uri, ) client.response_handler(response) end |
.resource_patch(client, resource, add_scopes: [], remove_scopes: []) ⇒ Object
Performs a specific patch operation.
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 = { 'Content-Type' => 'application/json-patch+json', 'If-Match' => '*', 'body' => scopes_body } response = client.rest_patch(scopes_uri, , client.api_version) client.response_handler(response) end |