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
Instance Method Summary collapse
-
#add_resource_scope(resource, scope) ⇒ Object
Add a scope to resource’s scope list.
-
#get_resource_scopes(resource) ⇒ Object
Gets a resource’s scope, containing a list of the scopes to which the resource is assigned.
-
#initialize(client, params = {}, api_ver = nil) ⇒ Scope
constructor
Create a resource object, associate it with a client, and set its properties.
-
#remove_resource_scope(resource, scope) ⇒ Object
Remove a scope from resource’s scope list.
-
#replace_resource_assigned_scopes(resource, scopes: []) ⇒ Object
Replaces a resource’s assigned scopes using the specified list of scope URIs.
-
#resource_patch(scopes_uri, operation, path, value = nil) ⇒ Object
Performs a specific patch operation.
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 |
Instance Method Details
#add_resource_scope(resource, scope) ⇒ Object
Add a scope to resource’s scope list
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.
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.
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.
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'] = { '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(scopes_uri, operation, path, value = nil) ⇒ Object
Performs a specific patch operation.
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 } = { 'Content-Type' => 'application/json-patch+json', 'If-Match' => '*', 'body' => [body] } response = @client.rest_patch(scopes_uri, , @api_version) @client.response_handler(response) end |