def netbox_create_or_update(self, config): logging.debug('It\'s a virtual machine') created = False updated = 0 hostname = get_hostname(config) vm = self.get_netbox_vm() vcpus = self.get_vcpus() memory = self.get_memory() if not vm: logging.debug('Creating Virtual machine..') cluster = self.get_netbox_cluster(config.virtual.cluster_name) vm = nb.virtualization.virtual_machines.create( name=hostname, cluster=cluster.id, vcpus=vcpus, memory=memory, ) created = True self.network = VirtualNetwork(server=self) self.network.create_or_update_netbox_network_cards() if not created and vm.vcpus != vcpus: vm.vcpus = vcpus updated += 1 elif not created and vm.memory != memory: vm.memory = memory updated += 1 if updated: vm.save()
def get_netbox_vm(self): hostname = get_hostname(config) vm = nb.virtualization.virtual_machines.get( name=hostname ) return vm