Class: Hpe3parSdk::HostSetManager
- Inherits:
-
Object
- Object
- Hpe3parSdk::HostSetManager
- Defined in:
- lib/Hpe3parSdk/host_set_manager.rb
Overview
Host Set Manager Rest API methods
Instance Method Summary collapse
- #add_hosts_to_host_set(set_name, setmembers) ⇒ Object
- #create_host_set(name, domain, comment, setmembers) ⇒ Object
- #delete_host_set(name) ⇒ Object
- #find_host_sets(host_name) ⇒ Object
- #get_host_set(name) ⇒ Object
- #get_host_sets ⇒ Object
- #host_in_host_set_exists?(set_name, host_name) ⇒ Boolean
- #host_set_exists?(host_name) ⇒ Boolean
-
#initialize(http, host_and_vv_set_filter_supported = false) ⇒ HostSetManager
constructor
A new instance of HostSetManager.
- #modify_host_set(name, action, setmembers, newName = nil, comment = nil) ⇒ Object
- #remove_hosts_from_host_set(set_name, setmembers) ⇒ Object
Constructor Details
#initialize(http, host_and_vv_set_filter_supported = false) ⇒ HostSetManager
Returns a new instance of HostSetManager.
20 21 22 23 24 |
# File 'lib/Hpe3parSdk/host_set_manager.rb', line 20 def initialize(http, host_and_vv_set_filter_supported = false) @http = http @host_set_uri = '/hostsets' @host_set_filter_supported = host_and_vv_set_filter_supported end |
Instance Method Details
#add_hosts_to_host_set(set_name, setmembers) ⇒ Object
87 88 89 |
# File 'lib/Hpe3parSdk/host_set_manager.rb', line 87 def add_hosts_to_host_set(set_name, setmembers) modify_host_set(set_name, SetCustomAction::MEM_ADD, setmembers) end |
#create_host_set(name, domain, comment, setmembers) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/Hpe3parSdk/host_set_manager.rb', line 44 def create_host_set(name, domain, comment, setmembers) info = { 'name' => name } info['domain'] = domain if domain info['comment'] = comment if comment if setmembers members = { 'setmembers' => setmembers } info = Util.merge_hash(info, members) end response = @http.post(@host_set_uri, body: info) if response[0] && response[0].include?('location') host_set_id = response[0]['location'].rpartition('/api/v1/hostsets/')[-1] return host_set_id else return nil end end |
#delete_host_set(name) ⇒ Object
65 66 67 |
# File 'lib/Hpe3parSdk/host_set_manager.rb', line 65 def delete_host_set(name) @http.delete("#{@host_set_uri}/#{name}") end |
#find_host_sets(host_name) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/Hpe3parSdk/host_set_manager.rb', line 95 def find_host_sets(host_name) host_sets = [] if @host_set_filter_supported query = %("setmembers EQ #{host_name}") response = @http.get("#{@host_set_uri}?query=#{query}") host_sets_list = response[1]['members'] host_sets_list.each do |host_set| host_sets.push(HostSet.new(host_set)) end else host_sets_list = get_host_sets host_sets_list.each do |host_set| if !host_set.setmembers.nil? && !host_set.setmembers.empty? && host_set.setmembers.include?(host_name) host_sets.push(host_set) end end end host_sets end |
#get_host_set(name) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/Hpe3parSdk/host_set_manager.rb', line 35 def get_host_set(name) if name.nil? || name.strip.empty? raise HPE3PARException.new(nil, 'HostSet name cannot be nil or empty') else response = @http.get("#{@host_set_uri}/#{name}") HostSet.new(response[1]) end end |
#get_host_sets ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/Hpe3parSdk/host_set_manager.rb', line 26 def get_host_sets response = @http.get(@host_set_uri) host_set_members = [] response[1]['members'].each do |host_set_member| host_set_members.push(HostSet.new(host_set_member)) end host_set_members end |
#host_in_host_set_exists?(set_name, host_name) ⇒ Boolean
124 125 |
# File 'lib/Hpe3parSdk/host_set_manager.rb', line 124 def host_in_host_set_exists?(set_name, host_name) end |
#host_set_exists?(host_name) ⇒ Boolean
115 116 117 118 119 120 121 122 |
# File 'lib/Hpe3parSdk/host_set_manager.rb', line 115 def host_set_exists?(host_name) begin get_host_set(host_name) return true rescue Hpe3parSdk::HTTPNotFound => ex return false end end |
#modify_host_set(name, action, setmembers, newName = nil, comment = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/Hpe3parSdk/host_set_manager.rb', line 69 def modify_host_set(name, action, setmembers, newName = nil, comment = nil) info = {} info['action'] = action if action info['newName'] = newName if newName info['comment'] = comment if comment if setmembers members = { 'setmembers' => setmembers } info = Util.merge_hash(info, members) end response = @http.put("#{@host_set_uri}/#{name}", body: info) response[1] end |
#remove_hosts_from_host_set(set_name, setmembers) ⇒ Object
91 92 93 |
# File 'lib/Hpe3parSdk/host_set_manager.rb', line 91 def remove_hosts_from_host_set(set_name, setmembers) modify_host_set(set_name, SetCustomAction::MEM_REMOVE, setmembers) end |