add config to set hostname command
This commit is contained in:
parent
9f7f29c190
commit
bc03274ca0
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('--log_level', default='debug')
|
||||||
p.add_argument('--netbox.url', help='Netbox URL')
|
p.add_argument('--netbox.url', help='Netbox URL')
|
||||||
p.add_argument('--netbox.token', help='Netbox API Token')
|
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',
|
p.add_argument('--datacenter_location.driver',
|
||||||
help='Datacenter location driver, ie: cmd, file')
|
help='Datacenter location driver, ie: cmd, file')
|
||||||
p.add_argument('--datacenter_location.driver_file',
|
p.add_argument('--datacenter_location.driver_file',
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import logging
|
import logging
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import socket
|
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
|
import netbox_agent.dmidecode as dmidecode
|
||||||
from netbox_agent.location import Datacenter, Rack
|
from netbox_agent.location import Datacenter, Rack
|
||||||
from netbox_agent.inventory import Inventory
|
from netbox_agent.inventory import Inventory
|
||||||
|
@ -85,7 +86,9 @@ class ServerBase():
|
||||||
return self.system[0]['Serial Number'].strip()
|
return self.system[0]['Serial Number'].strip()
|
||||||
|
|
||||||
def get_hostname(self):
|
def get_hostname(self):
|
||||||
|
if config.hostname_cmd is None:
|
||||||
return '{}'.format(socket.gethostname())
|
return '{}'.format(socket.gethostname())
|
||||||
|
return subprocess.getoutput(config.hostname_cmd)
|
||||||
|
|
||||||
def is_blade(self):
|
def is_blade(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -310,7 +313,7 @@ class ServerBase():
|
||||||
# check hostname
|
# check hostname
|
||||||
if server.name != self.get_hostname():
|
if server.name != self.get_hostname():
|
||||||
update += 1
|
update += 1
|
||||||
server.hostname = self.get_hostname()
|
server.name = self.get_hostname()
|
||||||
|
|
||||||
if config.update_all or config.update_location:
|
if config.update_all or config.update_location:
|
||||||
ret, server = self.update_netbox_location(server)
|
ret, server = self.update_netbox_location(server)
|
||||||
|
|
Loading…
Reference in a new issue