add rack unit and rack location functions
This commit is contained in:
parent
de07a4ccf1
commit
cafe502551
3 changed files with 21 additions and 42 deletions
|
|
@ -43,6 +43,10 @@ def get_config():
|
|||
p.add_argument('--virtual.cluster_name', help='Cluster name of VM')
|
||||
p.add_argument('--hostname_cmd', default=None,
|
||||
help="Command to output hostname, used as Device's name in netbox")
|
||||
p.add_argument('--rack_unit', default=None,
|
||||
help="The Unit location of server on rack")
|
||||
p.add_argument('--rack_face', default=None,
|
||||
help="Front/Rear of server on rack")
|
||||
p.add_argument('--device.platform', default=None,
|
||||
help='Override device platform. Here we use OS distribution.')
|
||||
p.add_argument('--device.tags', default=r'',
|
||||
|
|
@ -71,12 +75,6 @@ def get_config():
|
|||
p.add_argument('--rack_location.driver', help='Rack location driver, ie: cmd, file')
|
||||
p.add_argument('--rack_location.driver_file', help='Rack location custom driver file path')
|
||||
p.add_argument('--rack_location.regex', help='Rack location regex to extract Rack name')
|
||||
p.add_argument('--rack_unit.driver', help='Rack Unit driver, ie: cmd, file')
|
||||
p.add_argument('--rack_unit.driver_file', help='Rack Unit custom driver file path')
|
||||
p.add_argument('--rack_unit.regex', help='Rack Unit regex to extract Rack name')
|
||||
p.add_argument('--rack_face.driver', help='Rack Face driver, ie: cmd, file')
|
||||
p.add_argument('--rack_face.driver_file', help='Rack Face custom driver file path')
|
||||
p.add_argument('--rack_face.regex', help='Rack Face regex to extract Rack name')
|
||||
p.add_argument('--slot_location.driver', help='Slot location driver, ie: cmd, file')
|
||||
p.add_argument('--slot_location.driver_file', help='Slot location custom driver file path')
|
||||
p.add_argument('--slot_location.regex', help='Slot location regex to extract slot name')
|
||||
|
|
|
|||
|
|
@ -71,25 +71,6 @@ class Datacenter(LocationBase):
|
|||
regex = config.datacenter_location.regex
|
||||
super().__init__(driver, driver_value, driver_file, regex)
|
||||
|
||||
class Rack_Unit(LocationBase):
|
||||
def __init__(self):
|
||||
driver = config.rack_unit.driver.split(':')[0] if \
|
||||
config.rack_unit.driver else None
|
||||
driver_value = ':'.join(config.rack_unit.driver.split(':')[1:]) if \
|
||||
config.rack_unit.driver else None
|
||||
driver_file = config.rack_unit.driver_file
|
||||
regex = config.rack_unit.regex
|
||||
super().__init__(driver, driver_value, driver_file, regex)
|
||||
|
||||
class Rack_Face(LocationBase):
|
||||
def __init__(self):
|
||||
driver = config.rack_face.driver.split(':')[0] if \
|
||||
config.rack_face.driver else None
|
||||
driver_value = ':'.join(config.rack_face.driver.split(':')[1:]) if \
|
||||
config.rack_face.driver else None
|
||||
driver_file = config.rack_face.driver_file
|
||||
regex = config.rack_face.regex
|
||||
super().__init__(driver, driver_value, driver_file, regex)
|
||||
|
||||
class Rack(LocationBase):
|
||||
def __init__(self):
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import netbox_agent.dmidecode as dmidecode
|
|||
from netbox_agent.config import config
|
||||
from netbox_agent.config import netbox_instance as nb
|
||||
from netbox_agent.inventory import Inventory
|
||||
from netbox_agent.location import Datacenter, Rack, Tenant, Rack_Unit, Rack_Face
|
||||
from netbox_agent.location import Datacenter, Rack, Tenant
|
||||
from netbox_agent.misc import create_netbox_tags, get_device_role, get_device_type, get_device_platform
|
||||
from netbox_agent.network import ServerNetwork
|
||||
from netbox_agent.power import PowerSupply
|
||||
|
|
@ -88,11 +88,11 @@ class ServerBase():
|
|||
update = True
|
||||
server.site = nb_dc.id
|
||||
|
||||
if (
|
||||
server.rack
|
||||
and nb_rack
|
||||
and server.rack.id != nb_rack.id
|
||||
):
|
||||
# if (
|
||||
# server.rack
|
||||
# and nb_rack
|
||||
# and server.rack.id != nb_rack.id
|
||||
# ):
|
||||
logging.info('Rack location has changed from {} to {}, updating'.format(
|
||||
server.rack,
|
||||
nb_rack,
|
||||
|
|
@ -102,8 +102,8 @@ class ServerBase():
|
|||
if nb_rack is None:
|
||||
server.face = None
|
||||
server.position = None
|
||||
server.position = Rack_Unit().get()
|
||||
server.face = Rack_Face().get()
|
||||
server.position = config.rack_unit
|
||||
server.face = config.rack_face
|
||||
return update, server
|
||||
|
||||
def update_netbox_expansion_location(self, server, expansion):
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue