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

Direct Known Subclasses

Synergy::Scope

Defined Under Namespace

Modules: ScopeHelperMethods

Constant Summary collapse

BASE_URI =
'/rest/scopes'.freeze

Constants inherited from Resource

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!, #each, #eql?, #exists?, find_by, 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.

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:


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

#deletetrue

Delete resource from OneView

Returns:

  • (true)

    if resource was deleted successfully

Raises:


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

Parameters:

  • *resources (Array)

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

Raises:


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

Parameters:

  • *resources (Array)

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

Raises:


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

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