Skip to content

Commit

Permalink
Merge pull request #197 from opentechinstitute/hostname-update
Browse files Browse the repository at this point in the history
Hostname update
  • Loading branch information
jheretic committed Mar 10, 2014
2 parents 3bdf0de + 2971846 commit b9a2381
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions luasrc/model/cbi/commotion/basic_ns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ shn.addremove = false

--Create a value field for hostname
local hname = shn:option(Value, "hostname", translate("Node Name"), translate("The node name (hostname) is a unique name for this device, visible to other devices and users on the network. Name this device in the field provided."))
hname.datatype = "rangelength(1, 63)"
hname.datatype = "rangelength(1, 53)"
hname.rmempty = false

function hname.validate(self,value)
Expand All @@ -52,14 +52,19 @@ function hname.validate(self,value)
end

function hname.write(self, section, value)
local node_id = cnet.nodeid()
--check if the nodeid is the same and don't write hostname if it is. This means that if a person changes the hostname, but appends the old nodeif to the end of it the hostname will not change. But who in their right mind would do that.
hn, nid = value:match("(.-)%-([%d]*)$")
if nid and nid == node_id then
return true
hn = self:formvalue(section)
old_hn = self:cfgvalue(section)
if hn and hn == old_hn then
return true
else
local new_hn = value.."-"..string.sub(node_id, 1, 10)
return self.map:set(section, self.option, new_hn)
local node_id = cnet.nodeid()
if string.match(hn, node_id) then
-- requested hn already has nodeid
return self.map:set(section, self.option, hn)
else
local new_hn = hn.."-"..string.sub(node_id, 1, 10)
return self.map:set(section, self.option, new_hn)
end
end
end

Expand Down

0 comments on commit b9a2381

Please sign in to comment.