Class: OneviewSDK::API300::C7000::Scope
- Defined in:
- lib/oneview-sdk/resource/api300/c7000/scope.rb
Overview
Scope resource implementation for API300 C7k
Direct Known Subclasses
Defined Under Namespace
Modules: ScopeHelperMethods
Constant Summary collapse
- BASE_URI =
'/rest/scopes'.freeze
Constants inherited from Resource
Resource::DEFAULT_REQUEST_HEADER, Resource::UNIQUE_IDENTIFIERS
Instance Attribute Summary
Attributes inherited from Resource
#api_version, #client, #data, #logger
Instance Method Summary collapse
-
#change_resource_assignments(add_resources: [], remove_resources: []) ⇒ Object
Modifies scope membership by adding or removing resource assignments.
-
#delete ⇒ true
Delete resource from OneView.
-
#initialize(client, params = {}, api_ver = nil) ⇒ Scope
constructor
Create a resource object, associate it with a client, and set its properties.
-
#set_resources(*resources) ⇒ Object
Adds resource assignments.
-
#unset_resources(*resources) ⇒ Object
Removes resource assignments.
-
#update(attributes = {}) ⇒ Resource
Set data and save to OneView.
Methods inherited from Resource
#==, #[], #[]=, build_query, #create, #create!, #deep_merge!, #each, #eql?, #exists?, find_by, find_with_pagination, from_file, get_all, #like?, #refresh, #retrieve!, schema, #schema, #set, #set_all, #to_file
Constructor Details
#initialize(client, params = {}, api_ver = nil) ⇒ Scope
Create a resource object, associate it with a client, and set its properties.
26 27 28 29 30 |
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 26 def initialize(client, params = {}, api_ver = nil) @data ||= {} @data['type'] ||= 'Scope' super end |
Instance Method Details
#change_resource_assignments(add_resources: [], remove_resources: []) ⇒ Object
Modifies scope membership by adding or removing resource assignments
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 76 def change_resource_assignments(add_resources: [], remove_resources: []) if !add_resources.empty? || !remove_resources.empty? ensure_uri && ensure_client add_uris = ensure_and_get_uris(add_resources) remove_uris = ensure_and_get_uris(remove_resources) body = { 'addedResourceUris' => add_uris, 'removedResourceUris' => remove_uris } response = @client.rest_patch(@data['uri'] + '/resource-assignments', 'body' => body) @client.response_handler(response) end self end |
#delete ⇒ true
Delete resource from OneView
52 53 54 55 56 57 |
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 52 def delete ensure_client && ensure_uri response = @client.rest_delete(@data['uri'], { 'If-Match' => @data['eTag'] }, @api_version) @client.response_handler(response) true end |
#set_resources(*resources) ⇒ Object
Adds resource assignments
62 63 64 |
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 62 def set_resources(*resources) change_resource_assignments(add_resources: resources.flatten) end |
#unset_resources(*resources) ⇒ Object
Removes resource assignments
69 70 71 |
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 69 def unset_resources(*resources) change_resource_assignments(remove_resources: resources.flatten) end |
#update(attributes = {}) ⇒ Resource
Set data and save to OneView
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 37 def update(attributes = {}) set_all(attributes) ensure_client && ensure_uri = { 'If-Match' => @data.delete('eTag'), 'body' => @data } response = @client.rest_put(@data['uri'], , @api_version) @client.response_handler(response) self end |