Class: VagrantPlugins::GuestOpenWrt::Cap::ChangeHostName
- Inherits:
-
Object
- Object
- VagrantPlugins::GuestOpenWrt::Cap::ChangeHostName
- Defined in:
- lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb
Instance Attribute Summary collapse
-
#machine ⇒ Object
readonly
Returns the value of attribute machine.
-
#new_hostname ⇒ Object
readonly
Returns the value of attribute new_hostname.
Class Method Summary collapse
Instance Method Summary collapse
- #change! ⇒ Object
- #current_hostname ⇒ Object
- #execute(cmd, &block) ⇒ Object
- #get_current_hostname ⇒ Object
-
#initialize(machine, new_hostname) ⇒ ChangeHostName
constructor
A new instance of ChangeHostName.
- #should_change? ⇒ Boolean
- #update_etc_hostname ⇒ Object
Constructor Details
#initialize(machine, new_hostname) ⇒ ChangeHostName
Returns a new instance of ChangeHostName.
11 12 13 14 |
# File 'lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb', line 11 def initialize(machine, new_hostname) @machine = machine @new_hostname = new_hostname end |
Instance Attribute Details
#machine ⇒ Object (readonly)
Returns the value of attribute machine.
9 10 11 |
# File 'lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb', line 9 def machine @machine end |
#new_hostname ⇒ Object (readonly)
Returns the value of attribute new_hostname.
9 10 11 |
# File 'lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb', line 9 def new_hostname @new_hostname end |
Class Method Details
.change_host_name(machine, name) ⇒ Object
5 6 7 |
# File 'lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb', line 5 def self.change_host_name(machine, name) new(machine, name).change! end |
Instance Method Details
#change! ⇒ Object
16 17 18 19 20 |
# File 'lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb', line 16 def change! return unless should_change? update_etc_hostname end |
#current_hostname ⇒ Object
26 27 28 |
# File 'lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb', line 26 def current_hostname @current_hostname ||= get_current_hostname end |
#execute(cmd, &block) ⇒ Object
43 44 45 |
# File 'lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb', line 43 def execute(cmd, &block) machine.communicate.execute(cmd, &block) end |
#get_current_hostname ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb', line 30 def get_current_hostname hostname = "" execute "uci get system.@system[0].hostname" do |type, data| hostname = data.chomp if type == :stdout && hostname.empty? end hostname end |
#should_change? ⇒ Boolean
22 23 24 |
# File 'lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb', line 22 def should_change? new_hostname != current_hostname end |
#update_etc_hostname ⇒ Object
39 40 41 |
# File 'lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb', line 39 def update_etc_hostname execute(%{uci set system.@system[0].hostname="#{new_hostname}" && uci commit system}) end |