Module: ViprHost
- Included in:
- Vipr
- Defined in:
- lib/vipruby/objects/host.rb
Overview
The Following Host calls will get Host information for all tenants
Instance Method Summary collapse
-
#add_host(host_type = nil, ip_or_dns = nil, name = nil, user_name = nil, password = nil, port = nil, use_ssl = nil, discoverable = nil, auth = nil, cert = nil) ⇒ JSON
Add a host to ViPR.
-
#add_host_initiator(host_id = nil, protocol = nil, initiator_port = nil, initiator_node = nil, auth = nil, cert = nil) ⇒ Object
Add an initiator to a host in ViPR.
-
#check_host_get(host_id) ⇒ Boolean
private
Error Handling method to check for Missing Host ID param.
-
#check_host_post(host_type, ip_or_dns, name, user_name, password) ⇒ Boolean
private
Error Handling method to check for Missing Host Post params.
-
#check_host_post_initiator(protocol, initiator_port) ⇒ Boolean
private
Error Handling method to check for Initiator params.
-
#deactivate_host(host_id = nil, auth = nil, cert = nil) ⇒ JSON
Deactive and Remove a Host from ViPR.
-
#find_host_object(search_param, auth = nil, cert = nil) ⇒ JSON
Find and return query results for a host in ViPR.
-
#generate_host_post_json(host_type, ip_or_dns, name, port, user_name, password, use_ssl, discoverable) ⇒ JSON
generate JSON for Host POST.
-
#generate_initiators_json(protocol, initiator_node, initiator_port) ⇒ ARRAY
generate JSON for Initators POST.
-
#get_all_hosts(auth = nil, cert = nil) ⇒ JSON
Get all Host objects in ViPR.
-
#get_host(host_id = nil, auth = nil, cert = nil) ⇒ Hash
Get an individual host’s details in ViPR.
-
#host_exists?(hostname, auth = nil, cert = nil) ⇒ BOOLEAN
Determine if a host already exists in ViPR.
Instance Method Details
#add_host(host_type = nil, ip_or_dns = nil, name = nil, user_name = nil, password = nil, port = nil, use_ssl = nil, discoverable = nil, auth = nil, cert = nil) ⇒ JSON
Add a host to ViPR
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/vipruby/objects/host.rb', line 71 def add_host(host_type=nil, ip_or_dns=nil, name=nil, user_name=nil, password=nil, port=nil, use_ssl=nil, discoverable=nil, auth=nil, cert=nil) check_host_post(host_type, ip_or_dns, name, user_name, password) host_type = host_type.split('_').collect(&:capitalize).join if host_type == "Windows" use_ssl.nil? ? use_ssl = false : use_ssl if use_ssl == true port.nil? ? port = '5986' : port else port.nil? ? port = '5985' : port end discoverable.nil? ? discoverable = true : discoverable user_name.nil? ? user_name = "admin" : user_name password.nil? ? password = "#1Password" : password elsif host_type == "Linux" use_ssl.nil? ? use_ssl = false : use_ssl port.nil? ? port = '22' : port = port discoverable.nil? ? discoverable = true : discoverable user_name.nil? ? user_name = "admin" : user_name password.nil? ? password = "#1Password" : password elsif host_type == "Hpux" host_type = "HPUX" end rest_post(generate_host_post_json(host_type, ip_or_dns, name, port, user_name, password, use_ssl, discoverable), "#{@base_url}/tenants/#{@tenant_uid}/hosts", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert) end |
#add_host_initiator(host_id = nil, protocol = nil, initiator_port = nil, initiator_node = nil, auth = nil, cert = nil) ⇒ Object
Add an initiator to a host in ViPR
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/vipruby/objects/host.rb', line 107 def add_host_initiator(host_id=nil, protocol=nil, initiator_port=nil, initiator_node=nil, auth=nil, cert=nil) check_host_get(host_id) check_host_post_initiator(protocol, initiator_port) protocol = protocol.upcase if protocol == "ISCSI" protocol = "iSCSI" end initiator_payload_array = generate_initiators_json(protocol, initiator_node, initiator_port) initiator_payload_array.each do |i| rest_post(i, "#{@base_url}/compute/hosts/#{host_id}/initiators", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert) end end |
#check_host_get(host_id) ⇒ Boolean (private)
Error Handling method to check for Missing Host ID param. If the pass fails, an error exception is raised
215 216 217 218 219 |
# File 'lib/vipruby/objects/host.rb', line 215 def check_host_get(host_id) if host_id == nil raise "Missing the Required param (host_id). Find the host_id by using the get_all_hosts method." end end |
#check_host_post(host_type, ip_or_dns, name, user_name, password) ⇒ Boolean (private)
Error Handling method to check for Missing Host Post params. If the pass fails, an error exception is raised
203 204 205 206 207 |
# File 'lib/vipruby/objects/host.rb', line 203 def check_host_post(host_type, ip_or_dns, name, user_name, password) if host_type == nil || ip_or_dns == nil || name == nil raise "Missing a Required param (host_type, ip_or_dns, name)" end end |
#check_host_post_initiator(protocol, initiator_port) ⇒ Boolean (private)
Error Handling method to check for Initiator params. If the pass fails, an error exception is raised
228 229 230 231 232 |
# File 'lib/vipruby/objects/host.rb', line 228 def check_host_post_initiator(protocol, initiator_port) if protocol== nil || initiator_port == nil raise "Missing the Required param (protocol or initiator_port)." end end |
#deactivate_host(host_id = nil, auth = nil, cert = nil) ⇒ JSON
Deactive and Remove a Host from ViPR
154 155 156 157 |
# File 'lib/vipruby/objects/host.rb', line 154 def deactivate_host(host_id=nil, auth=nil, cert=nil) check_host_get(host_id) rest_post(nil, "#{@base_url}/compute/hosts/#{host_id}/deactivate", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert) end |
#find_host_object(search_param, auth = nil, cert = nil) ⇒ JSON
Find and return query results for a host in ViPR
187 188 189 |
# File 'lib/vipruby/objects/host.rb', line 187 def find_host_object(search_param, auth=nil, cert=nil) rest_get("#{@base_url}/compute/hosts/search?name=#{search_param}", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert) end |
#generate_host_post_json(host_type, ip_or_dns, name, port, user_name, password, use_ssl, discoverable) ⇒ JSON
generate JSON for Host POST
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vipruby/objects/host.rb', line 19 def generate_host_post_json(host_type, ip_or_dns, name, port, user_name, password, use_ssl, discoverable) payload = { type: host_type, host_name: ip_or_dns, name: name, port_number: port, user_name: user_name, password: password, use_ssl: use_ssl, discoverable: discoverable }.to_json return payload end |
#generate_initiators_json(protocol, initiator_node, initiator_port) ⇒ ARRAY
generate JSON for Initators POST
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vipruby/objects/host.rb', line 41 def generate_initiators_json(protocol, initiator_node, initiator_port) initiator_json = [] initiator_port.each do |initiator| initiator_json << { protocol: protocol, initiator_node: initiator_node, initiator_port: initiator }.to_json end return initiator_json end |
#get_all_hosts(auth = nil, cert = nil) ⇒ JSON
Get all Host objects in ViPR
127 128 129 |
# File 'lib/vipruby/objects/host.rb', line 127 def get_all_hosts(auth=nil, cert=nil) rest_get("#{@base_url}/tenants/#{@tenant_uid}/hosts", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert) end |
#get_host(host_id = nil, auth = nil, cert = nil) ⇒ Hash
Get an individual host’s details in ViPR
140 141 142 143 |
# File 'lib/vipruby/objects/host.rb', line 140 def get_host(host_id=nil, auth=nil, cert=nil) check_host_get(host_id) rest_get("#{@base_url}/compute/hosts/#{host_id}", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert) end |
#host_exists?(hostname, auth = nil, cert = nil) ⇒ BOOLEAN
Determine if a host already exists in ViPR
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/vipruby/objects/host.rb', line 167 def host_exists?(hostname, auth=nil, cert=nil) hostname = hostname.downcase host_array = [] hosts = get_all_hosts hosts.each do |key, value| value.each do |k| host_array << k['name'].to_s.downcase end end host_array.include?(hostname) end |