Skip to content

Commit

Permalink
Merge pull request #1785 from GabrielSVinha/provider_discovery
Browse files Browse the repository at this point in the history
Change discover to make lenovo provider discovery
  • Loading branch information
Dan Clarizio committed Aug 15, 2017
2 parents 589f6f5 + 30b1b97 commit 02c9214
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
32 changes: 31 additions & 1 deletion app/controllers/mixins/actions/host_actions/discover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,19 @@ def discover
render :action => 'discover'
else
begin
if request.parameters[:controller] != "ems_cloud"
if request.parameters[:controller] == "ems_physical_infra"
validate_addresses(from_ip, to_ip, params[:port])
@discover_type_checked.each do |type|
physical_infra_manager = ManageIQ::Providers::PhysicalInfraManager.subclasses.detect do |ems|
ems.ems_type == type
end
ip_address = from_ip.split(".")
ip_address.last.to_i.upto(to_ip.split(".").last.to_i) do |addr|
ip = ip_address[0].to_s + "." + ip_address[1].to_s + "." + ip_address[2] + "." + addr.to_s
physical_infra_manager.discover_queue(ip, params[:port])
end
end
elsif request.parameters[:controller] != "ems_cloud"
if params[:discover_type_ipmi].to_s == "1"
options = {:discover_types => discover_type, :credentials => {:ipmi => {:userid => @userid, :password => @password}}}
else
Expand Down Expand Up @@ -214,6 +226,24 @@ def discover_type(controller)
@discover_type_selected = @discover_type.first.try!(:last)
end
end

def validate_addresses(from_ip, to_ip, port)
pattern = /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
raise _("Starting address is malformed") if (from_ip =~ pattern).nil?
raise _("Ending address is malformed") if (to_ip =~ pattern).nil?

from_ip.split(".").each_index do |i|
if to_ip.split(".")[i].to_i > 255 || to_ip.split(".")[i].to_i > 255
raise _("IP address octets must be 0 to 255")
end
if from_ip.split(".")[i].to_i > to_ip.split(".")[i].to_i
raise _("Ending address must be greater than starting address")
end
end

raise _("Invalid port number") if port.to_i <= 0
raise _("Port number must be 1 to 65535") if port.to_i > 65_535
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper/discover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def discover_type(dtype)
"scvmm" => _("Microsoft System Center VMM"),
"virtualcenter" => _("VMware vCenter"),
"vmwareserver" => _("VMware Server"),
"lxca" => _("Lenovo XClarity Administrator")
"lenovo_ph_infra" => _("Lenovo XClarity Administrator")
}

if dtypes.key?(dtype)
Expand Down
10 changes: 10 additions & 0 deletions app/views/ems_physical_infra/discover.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
:maxlength => 3,
"data-miq_observe" => {:interval => '.5',
:url => url}.to_json)
.form-group
%label.col-md-2.control-label
= _("Port")
.col-md-8
= text_field_tag('port',
@port,
:size => '5',
:maxlength => '5',
"data-miq_observe" => {:interval => '.5',
:url => url}.to_json)
.pull-right
= button_tag(_("Start"),
:class => "btn btn-primary",
Expand Down

0 comments on commit 02c9214

Please sign in to comment.