pizza box (server) netbox creation

This commit is contained in:
Solvik Blum 2019-08-03 15:57:06 +02:00
parent 8960df61dc
commit ab4ea42466
2 changed files with 31 additions and 6 deletions

View file

@ -12,10 +12,9 @@ MANUFACTURERS = {
def main():
manufacturer = dmidecode.get_by_type('Chassis')[0].get('Manufacturer')
print(manufacturer)
server = MANUFACTURERS[manufacturer](dmidecode)
pprint(dmidecode.parse())
print(server.get_product_name())
print(server.get_blade_slot())
print(server.get_chassis())
print(server.get_service_tag())
print(server.get_chassis_service_tag())

View file

@ -74,7 +74,7 @@ class ServerBase():
name='Server Chassis',
)
datacenter = nb.dcim.sites.get(
name='DC3'
name='DC3' # FIXME: datacenter support
)
new_chassis = nb.dcim.devices.create(
name=''.format(),
@ -92,17 +92,41 @@ class ServerBase():
device_type = nb.dcim.device_types.get(
model=self.get_product_name(),
)
datacenter = nb.dcim.sites.get(
name='DC3' # FIXME: datacenter support
)
new_blade = nb.dcim.devices.create(
name='{}'.format(socket.gethostname()),
serial=self.get_service_tag(),
device_role=device_role.id,
device_type=device_type.id,
parent_device=chassis.id,
site='1',
site=datacenter.id,
)
return new_blade
def _netbox_create_server(self):
device_role = nb.dcim.device_roles.get(
name='Server',
)
device_type = nb.dcim.device_types.get(
model=self.get_product_name(),
)
if not device_type:
raise Exception('Chassis "{}" doesn\'t exist'.format(self.get_chassis()))
datacenter = nb.dcim.sites.get(
name='DC3' # FIXME: datacenter support
)
new_server = nb.dcim.devices.create(
name='{}'.format(socket.gethostname()),
serial=self.get_service_tag(),
device_role=device_role.id,
device_type=device_type.id,
site=datacenter.id,
)
return new_server
def netbox_create(self):
if self.is_blade():
# let's find the blade
@ -128,4 +152,6 @@ class ServerBase():
device_bay.save()
else:
# FIXME : handle pizza box
pass
server = nb.dcim.devices.get(serial=self.get_service_tag())
if not server:
self._netbox_create_server()