Class: OneviewSDK::API300::C7000::Scope

Inherits:
Resource
  • Object
show all
Defined in:
lib/oneview-sdk/resource/api300/c7000/scope.rb

Overview

Scope resource implementation for API300 C7k

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

Methods inherited from Resource

#==, #[], #[]=, build_query, #create, #create!, #deep_merge!, #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

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. Defaults to the client.api_version if it exists, or the OneviewSDK::Client::DEFAULT_API_VERSION.



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

Parameters:

  • resources (Array)

    The array of resources (or any number of resources separated by comma)

Raises:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 74

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(header = {}) ⇒ true

Delete resource from OneView

Parameters:

  • header (Hash) (defaults to: {})

    The header options for the request (key-value pairs)

Returns:

  • (true)

    if resource was deleted successfully

Raises:



53
54
55
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 53

def delete(header = {})
  super(DEFAULT_REQUEST_HEADER.merge(header).merge('If-Match' => @data['eTag']))
end

#set_resources(*resources) ⇒ Object

Adds resource assignments

Parameters:

  • *resources (Array)

    The array of resources (or any number of resources separated by comma)

Raises:



60
61
62
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 60

def set_resources(*resources)
  change_resource_assignments(add_resources: resources.flatten)
end

#unset_resources(*resources) ⇒ Object

Removes resource assignments

Parameters:

  • *resources (Array)

    The array of resources (or any number of resources separated by comma)

Raises:



67
68
69
# File 'lib/oneview-sdk/resource/api300/c7000/scope.rb', line 67

def unset_resources(*resources)
  change_resource_assignments(remove_resources: resources.flatten)
end

#update(attributes = {}) ⇒ Resource

Set data and save to OneView

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes to add/change for this resource (key-value pairs)

Returns:

Raises:



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
  options = {
    'If-Match' => @data.delete('eTag'),
    'body' => @data
  }
  response = @client.rest_put(@data['uri'], options, @api_version)
  @client.response_handler(response)
  self
end