add config to set hostname command (#81)
This commit is contained in:
parent
93af39e780
commit
5f851ec619
2 changed files with 8 additions and 3 deletions
|
@ -27,6 +27,8 @@ def get_config():
|
|||
p.add_argument('--log_level', default='debug')
|
||||
p.add_argument('--netbox.url', help='Netbox URL')
|
||||
p.add_argument('--netbox.token', help='Netbox API Token')
|
||||
p.add_argument('--hostname_cmd', default=None,
|
||||
help="Command to output hostname, used as Device's name in netbox")
|
||||
p.add_argument('--datacenter_location.driver',
|
||||
help='Datacenter location driver, ie: cmd, file')
|
||||
p.add_argument('--datacenter_location.driver_file',
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import logging
|
||||
from pprint import pprint
|
||||
import socket
|
||||
import subprocess
|
||||
|
||||
from netbox_agent.config import netbox_instance as nb
|
||||
from netbox_agent.config import netbox_instance as nb, config
|
||||
import netbox_agent.dmidecode as dmidecode
|
||||
from netbox_agent.location import Datacenter, Rack
|
||||
from netbox_agent.inventory import Inventory
|
||||
|
@ -85,7 +86,9 @@ class ServerBase():
|
|||
return self.system[0]['Serial Number'].strip()
|
||||
|
||||
def get_hostname(self):
|
||||
return '{}'.format(socket.gethostname())
|
||||
if config.hostname_cmd is None:
|
||||
return '{}'.format(socket.gethostname())
|
||||
return subprocess.getoutput(config.hostname_cmd)
|
||||
|
||||
def is_blade(self):
|
||||
raise NotImplementedError
|
||||
|
@ -310,7 +313,7 @@ class ServerBase():
|
|||
# check hostname
|
||||
if server.name != self.get_hostname():
|
||||
update += 1
|
||||
server.hostname = self.get_hostname()
|
||||
server.name = self.get_hostname()
|
||||
|
||||
if config.update_all or config.update_location:
|
||||
ret, server = self.update_netbox_location(server)
|
||||
|
|
Loading…
Reference in a new issue