-
Notifications
You must be signed in to change notification settings - Fork 30
Added method to get and set hostname to Hosts class #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
module LinuxAdmin | ||
class Hosts | ||
include Common | ||
|
||
attr_accessor :filename | ||
attr_accessor :raw_lines | ||
attr_accessor :parsed_file | ||
|
@@ -36,6 +38,20 @@ def update_entry(address, hostname, comment = nil) | |
end | ||
end | ||
|
||
def hostname=(name) | ||
if cmd?("hostnamectl") | ||
run!(cmd('hostnamectl'), :params => ['set-hostname', name]) | ||
else | ||
File.write("/etc/hostname", name) | ||
run!(cmd('hostname'), :params => {:file => "/etc/hostname"}) | ||
end | ||
end | ||
|
||
def hostname | ||
result = run(cmd("hostname")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already require run(cmd("hostname")).output.presence There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about what will be on output. It depends really on what |
||
result.success? ? result.output : nil | ||
end | ||
|
||
private | ||
def parse_file | ||
@parsed_file = [] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to add the logic to add the machine's IP address to the
/etc/hosts
file (https://github.com/ManageIQ/manageiq-appliance/blob/master/LINK/usr/bin/miqnet.sh#L167) here or have the caller do it in a separate call?@Fryguy @bdunne
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are setting ip address, would you ensure that if you set a different ip address, it clears out the old ip address from
/etc/hosts
If you are changing the hostname, do we also clear that out.
man, the use cases around this are complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say that the safest way to go would be to do as little as possible with each call. I don't really want to assume what people will want to do with these tools. I think it will be more clear from the calling code to do something like this https://github.com/ManageIQ/manageiq/pull/4558/files#diff-16bd2bb3c0abfe4c0381896614e7b987R238