def _add_server(self, openstack_server, server_id, project): """add new server to ralph""" try: flavor = self._get_flavors()[openstack_server['flavor_id']] except KeyError: logger.warning('Flavor %s not found for host %s', openstack_server['flavor_id'], openstack_server) return logger.info('Creating new server %s (%s)', server_id, openstack_server['hostname']) new_server = CloudHost( hostname=openstack_server['hostname'], cloudflavor=flavor, parent=project, host_id=server_id, hypervisor=self._get_hypervisor(openstack_server['hypervisor'], server_id), cloudprovider=self.cloud_provider, image_name=openstack_server['image'], ) # workaround - created field has auto_now_add attribute new_server.save() new_server.created = datetime.strptime(openstack_server['created'], self.DATETIME_FORMAT) self._save_object(new_server, 'add server %s' % new_server.hostname) new_server.tags.add(openstack_server['tag']) with transaction.atomic(), revisions.create_revision(): new_server.ip_addresses = openstack_server['ips'] revisions.set_comment('Assign ip addresses to a host')
def test_cleanup_security_scan_transition(self): security_scan = SecurityScanFactory(base_object=self.cloud_host) self.assertEqual(self.cloud_host.securityscan, security_scan) self.assertIsNotNone(self.cloud_host.securityscan.id) CloudHost.cleanup_security_scans((self.cloud_host, )) self.assertIsNone(self.cloud_host.securityscan.id)