Skip to content

Commit

Permalink
Merge pull request #238 from bdunne/drop_network_config
Browse files Browse the repository at this point in the history
Remove network configuration from the appliance console
  • Loading branch information
Fryguy authored Mar 5, 2024
2 parents c5dd78f + 5e89e7a commit ac9cb0b
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 201 deletions.
155 changes: 0 additions & 155 deletions bin/appliance_console
Original file line number Diff line number Diff line change
Expand Up @@ -149,161 +149,6 @@ To modify the configuration, use a web browser to access the management page.
clear_screen
selection = ask_with_menu("Advanced Setting", AS_OPTIONS, nil, true)
case selection
when I18n.t('advanced_settings.networking')
options = {
'Set DHCP Network Configuration' => 'dhcp',
'Set IPv4 Static Network Configuration' => 'static',
'Set IPv6 Static Network Configuration' => 'static6',
'Test Network Configuration' => 'testnet',
'Set Hostname' => 'hostname'
}
case ask_with_menu('Network Configuration', options)
when 'dhcp'
say("DHCP Network Configuration\n\n")

ipv4 = agree('Enable DHCP for IPv4 network configuration? (Y/N): ')
ipv6 = agree('Enable DHCP for IPv6 network configuration? (Y/N): ')

if ipv4 || ipv6
say("\nApplying DHCP network configuration...")

resolv = LinuxAdmin::Dns.new
resolv.search_order = []
resolv.nameservers = []
resolv.save

eth0.enable_dhcp if ipv4
eth0.enable_dhcp6 if ipv6
eth0.save

File.write(CLOUD_INIT_NETWORK_CONFIG_FILE, CLOUD_INIT_DISABLE_NETWORK_CONFIG)
say("\nAfter completing the appliance configuration, please restart #{I18n.t("product.name")} server processes.")
press_any_key
end
when 'static'
say("Static Network Configuration\n\n")
say("Enter the new static network configuration settings.\n\n")

new_ip = ask_for_ipv4("IP Address", ip)
new_mask = ask_for_ipv4("Netmask", mask)
new_gw = ask_for_ipv4("Gateway", gw)
new_dns1 = ask_for_ip("Primary DNS", dns1)
new_dns2 = ask_for_ip_or_none("Secondary DNS (Enter 'none' for no value)", dns2)

new_search_order = ask_for_many("domain", "Domain search order", order)

clear_screen
say(<<-EOL)
Static Network Configuration
IP Address: #{new_ip}
Netmask: #{new_mask}
Gateway: #{new_gw}
Primary DNS: #{new_dns1}
Secondary DNS: #{new_dns2}
Search Order: #{new_search_order.join(" ")}
EOL

if agree("Apply static network configuration? (Y/N)")
say("\nApplying static network configuration...")

resolv = LinuxAdmin::Dns.new
resolv.search_order = []
resolv.nameservers = []
resolv.save

begin
network_configured = eth0.apply_static(new_ip, new_mask, new_gw, [new_dns1, new_dns2], new_search_order)
rescue ArgumentError => e
say("\nNetwork configuration failed: #{e.message}")
press_any_key
next
end

unless network_configured
say("\nNetwork interface failed to start using the values supplied.")
press_any_key
next
end

File.write(CLOUD_INIT_NETWORK_CONFIG_FILE, CLOUD_INIT_DISABLE_NETWORK_CONFIG)
say("\nAfter completing the appliance configuration, please restart #{I18n.t("product.name")} server processes.")
press_any_key
end

when 'static6'
say("IPv6: Static Network Configuration\n\n")
say("Enter the new static network configuration settings.\n\n")

new_ip = ask_for_ipv6('IP Address', eth0.address6)
new_prefix = ask_for_integer('IPv6 prefix length', 1..127, eth0.prefix6 || 64)
new_gw = ask_for_ipv6('Default gateway', eth0.gateway6)
new_dns1 = ask_for_ip('Primary DNS', dns1)
new_dns2 = ask_for_ip_or_none("Secondary DNS (Enter 'none' for no value)", dns2)

new_search_order = ask_for_many('domain', 'Domain search order', order)

clear_screen
say(<<-EOL)
Static Network Configuration
IP Address: #{new_ip}/#{new_prefix}
Gateway: #{new_gw}
Primary DNS: #{new_dns1}
Secondary DNS: #{new_dns2}
Search Order: #{new_search_order.join(" ")}
EOL

if agree('Apply static network configuration? (Y/N)')
say("\nApplying static network configuration...")

resolv = LinuxAdmin::Dns.new
resolv.search_order = []
resolv.nameservers = []
resolv.save

begin
network_configured = eth0.apply_static6(new_ip, new_prefix, new_gw, [new_dns1, new_dns2], new_search_order)
rescue ArgumentError => e
say("\nNetwork configuration failed: #{e.message}")
press_any_key
next
end

unless network_configured
say("\nNetwork interface failed to start using the values supplied.")
press_any_key
next
end

File.write(CLOUD_INIT_NETWORK_CONFIG_FILE, CLOUD_INIT_DISABLE_NETWORK_CONFIG)
say("\nAfter completing the appliance configuration, please restart #{I18n.t("product.name")} server processes.")
press_any_key
end

when 'testnet'
ManageIQ::ApplianceConsole::Utilities.test_network

when 'hostname'
say("Hostname Configuration\n\n")
new_host = just_ask("new hostname", host, HOSTNAME_REGEXP, "Please enter a valid hostname")

if new_host != host
say("Applying new hostname...")
system_hosts = LinuxAdmin::Hosts.new

system_hosts.parsed_file.each { |line| line[:hosts].to_a.delete(host) } unless host =~ /^localhost.*/

system_hosts.hostname = new_host
system_hosts.set_loopback_hostname(new_host)
system_hosts.save

press_any_key
end
end

when I18n.t("advanced_settings.httpdauth")
say("#{selection}\n\n")

Expand Down
1 change: 0 additions & 1 deletion lib/manageiq/appliance_console/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def run
system_hosts.hostname = options[:host]
system_hosts.set_loopback_hostname(options[:host])
system_hosts.save
LinuxAdmin::Service.new("network").restart
end
create_key if key?
set_db if database?
Expand Down
20 changes: 0 additions & 20 deletions lib/manageiq/appliance_console/prompts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,6 @@ def ask_for_ip(prompt, default, validate = IP_REGEXP, error_text = "a valid IP A
just_ask(prompt, default, validate, error_text, &block)
end

def ask_for_ip_or_none(prompt, default = nil)
ask_for_ip(prompt, default, Regexp.union(NONE_REGEXP, IP_REGEXP)).gsub(NONE_REGEXP, "")
end

def ask_for_ipv4(prompt, default)
ask_for_ip(prompt, default, IPV4_REGEXP)
end

def ask_for_ipv4_or_none(prompt, default = nil)
ask_for_ip(prompt, default, Regexp.union(NONE_REGEXP, IPV4_REGEXP)).gsub(NONE_REGEXP, "")
end

def ask_for_ipv6(prompt, default)
ask_for_ip(prompt, default, IPV6_REGEXP)
end

def ask_for_ipv6_or_none(prompt, default = nil)
ask_for_ip(prompt, default, Regexp.union(IPV6_REGEXP, NONE_REGEXP)).gsub(NONE_REGEXP, '')
end

def ask_for_hostname(prompt, default = nil, validate = HOSTNAME_REGEXP, error_text = "a valid Hostname.", &block)
just_ask(prompt, default, validate, error_text, &block)
end
Expand Down
4 changes: 1 addition & 3 deletions locales/appliance/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ en:
name: ManageIQ
advanced_settings:
menu_order:
- networking
- dbbackup
- dbdump
- dbrestore
Expand All @@ -21,7 +20,6 @@ en:
- shutdown
- summary
- quit
networking: Configure Network
dbbackup: Create Database Backup
dbdump: Create Database Dump
dbrestore: Restore Database From Backup
Expand All @@ -41,4 +39,4 @@ en:
database_admin:
local: Local file
sample_url:
nfs: nfs://host.mydomain.com/exported/my_exported_folder/db.backup
nfs: nfs://host.example.com/exported/my_exported_folder/db.backup
2 changes: 0 additions & 2 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
it "should set hostname if defined" do
expect_any_instance_of(LinuxAdmin::Hosts).to receive(:hostname=).with('host1')
expect_any_instance_of(LinuxAdmin::Hosts).to receive(:save).and_return(true)
expect_any_instance_of(LinuxAdmin::Service.new("test").class).to receive(:restart).and_return(true)

subject.parse(%w(--host host1)).run
end
Expand Down Expand Up @@ -320,7 +319,6 @@
it "should not post_activate install ipa (aside: testing passing in host" do
expect_any_instance_of(LinuxAdmin::Hosts).to receive(:hostname=).with("client.domain.com")
expect_any_instance_of(LinuxAdmin::Hosts).to receive(:save).and_return(true)
expect_any_instance_of(LinuxAdmin::Service.new("test").class).to receive(:restart).and_return(true)
expect_any_instance_of(LinuxAdmin::Hosts).to_not receive(:hostname)
expect(ManageIQ::ApplianceConsole::ExternalHttpdAuthentication).to receive(:ipa_client_configured?).and_return(false)
expect(ManageIQ::ApplianceConsole::ExternalHttpdAuthentication).to receive(:new)
Expand Down
20 changes: 0 additions & 20 deletions spec/prompts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,6 @@
expect(subject.ask_for_ip('prompt', '1.1.1.1')).to eq('::1')
end

context "#or_none" do
it "should handle default" do
say ""
expect(subject.ask_for_ipv4_or_none("prompt", "1.1.1.1")).to eq("1.1.1.1")
expect_heard("Enter the prompt: |1.1.1.1| ")
end

it "should handle blank" do
say ""
expect(subject.ask_for_ipv4_or_none("prompt")).to eq("")
expect_heard("Enter the prompt: ")
end

it "should handle none" do
say "none"
expect(subject.ask_for_ipv4_or_none("prompt", "1.1.1.1")).to eq("")
expect_heard("Enter the prompt: |1.1.1.1| ")
end
end

context "#or hostname" do
it "should handle default" do
say ""
Expand Down

0 comments on commit ac9cb0b

Please sign in to comment.