Class: Purest::PhysicalArray

Inherits:
Rest show all
Defined in:
lib/purest/physical_array.rb

Constant Summary collapse

GET_PARAMS =
[:action, :banner, :connection_key, :controllers, :historical,
:idle_timeout, :ntpserver, :phonehome, :proxy, :relayhost, :scsi_timeout,
:senderdomain, :space, :syslogserver, :throttle]

Instance Method Summary collapse

Methods inherited from Rest

access_method?, #authenticated?, #concat_url, #initialize, #logout, method_missing, #use_named_parameter

Constructor Details

This class inherits a constructor from Purest::Rest

Instance Method Details

#create(options = nil) ⇒ Object

Create a connection between two arrays

Parameters:

  • options (Hash) (defaults to: nil)

    options to pass



41
42
43
44
45
46
47
48
49
50
# File 'lib/purest/physical_array.rb', line 41

def create(options = nil)
  @options = options

  raw_resp = @conn.post do |req|
    req.url "/api/#{Purest.configuration.api_version}/array/connection"
    req.body = @options.to_json
  end

  JSON.parse(raw_resp.body, :symbolize_names => true)
end

#delete(options = nil) ⇒ Object

Disconnect one array from another

Parameters:

  • options (Hash) (defaults to: nil)

    options to pass in



94
95
96
97
98
99
100
# File 'lib/purest/physical_array.rb', line 94

def delete(options = nil)
  @options = options

  raw_resp = @conn.delete do |req|
    req.url "/api/#{Purest.configuration.api_version}/array/connection/#{@options[:connected_array]}"
  end
end

#get(options = nil) ⇒ Object

Get a list of hosts, GET

Parameters:

  • options (Hash) (defaults to: nil)

    options to pass



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/purest/physical_array.rb', line 13

def get(options = nil)
  @options = options
  create_session unless authenticated?

  raw_resp = @conn.get do |req|
    url = ["/api/#{Purest.configuration.api_version}/array"]

    # Map /connection, /console_lock, /phonehome, /remoteassist
    # depending on what was passed in
    [:connection, :console_lock, :phonehome, :remoteassist].each do |path|
      url.map!{|u| u + "/#{path.to_s}"} if !@options.nil? && @options[path]
    end

    # Generate array, consisting of url parts, to be built
    # by concat_url method below
    GET_PARAMS.each do |param|
      url += self.send(:"use_#{param}",@options)
    end

    # Build url from array of parts, send request
    req.url concat_url url
  end

  JSON.parse(raw_resp.body, :symbolize_names => true)
end

#update(options = nil) ⇒ Object

Update attributes on an array, PUT

Parameters:

  • options (Hash) (defaults to: nil)

    options to pass in



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/purest/physical_array.rb', line 54

def update(options = nil)
  @options = options

  raw_resp = @conn.put do |req|
    url = ["/api/#{Purest.configuration.api_version}/array"]

    if !@options.nil? && @options[:connected_array]
      url.map!{|u| u + "/connection/#{@options[:connected_array]}"}
    end

    # Small conditional to ease remote assistance connecting/disconnecting
    if !@options.nil? && @options[:remote_assist]
      url.map!{|u| u + "/remoteassist"}
      @options[:action] = @options.delete(:remote_assist)
    end

    # Small loop to ease console locking and home phoning
    [:console_lock, :phonehome].each do |path|
      if !@options.nil? && @options[path]
        url.map!{|u| u + "/#{path.to_s}"}
        @options[:enabled] = @options.delete(path)
      end
    end

    # Keeping things consistent
    @options[:name] = @options.delete(:new_name) if @options[:new_name]

    # Don't send this as part of the JSON body if it's present
    # in the options hash, as it's not a valid param
    @options.delete(:connected_array)
    req.body = @options.to_json

    req.url concat_url url
  end

  JSON.parse(raw_resp.body, :symbolize_names => true)
end