def _validate(body): """Validate that the request has all the required parameters""" InstanceController._validate_body_not_empty(body) try: body['instance'] body['instance']['flavorRef'] vol_enabled = utils.bool_from_string( config.Config.get('reddwarf_volume_support', 'True')) must_have_vol = utils.bool_from_string( config.Config.get('reddwarf_must_use_volume', 'False')) if vol_enabled: if body['instance'].get('volume', None): if body['instance']['volume'].get('size', None): volume_size = body['instance']['volume']['size'] InstanceController._validate_volume_size(volume_size) elif must_have_vol: raise exception.MissingKey(key="size") elif must_have_vol: raise exception.MissingKey(key="volume") except KeyError as e: LOG.error(_("Create Instance Required field(s) - %s") % e) raise exception.ReddwarfError("Required element/key - %s " "was not specified" % e)
def _delete_resources(self): try: self.server.delete() except Exception as ex: LOG.error("Error during delete compute server %s " % self.server.id) LOG.error(ex) try: dns_support = config.Config.get("reddwarf_dns_support", 'False') LOG.debug(_("reddwarf dns support = %s") % dns_support) if utils.bool_from_string(dns_support): dns_api = create_dns_client(self.context) dns_api.delete_instance_entry(instance_id=self.db_info.id) except Exception as ex: LOG.error("Error during dns entry for instance %s " % self.db_info.id) LOG.error(ex) # Poll until the server is gone. def server_is_finished(): try: server_id = self.db_info.compute_instance_id server = self.nova_client.servers.get(server_id) if server.status not in ['SHUTDOWN', 'ACTIVE']: msg = "Server %s got into ERROR status during delete " \ "of instance %s!" % (server.id, self.id) LOG.error(msg) return False except nova_exceptions.NotFound: return True poll_until(server_is_finished, sleep_time=2, time_out=int(config.Config.get('server_delete_time_out')))
def create(cls, context, name, flavor_id, image_id, databases, users, service_type, volume_size): client = create_nova_client(context) try: flavor = client.flavors.get(flavor_id) except nova_exceptions.NotFound: raise exception.FlavorNotFound(uuid=flavor_id) db_info = DBInstance.create(name=name, flavor_id=flavor_id, tenant_id=context.tenant, volume_size=volume_size, task_status=InstanceTasks.BUILDING) LOG.debug(_("Tenant %s created new Reddwarf instance %s...") % (context.tenant, db_info.id)) service_status = InstanceServiceStatus.create( instance_id=db_info.id, status=ServiceStatuses.NEW) dns_support = config.Config.get("reddwarf_dns_support", 'False') if utils.bool_from_string(dns_support): dns_client = create_dns_client(context) hostname = dns_client.determine_hostname(db_info.id) db_info.hostname = hostname db_info.save() task_api.API(context).create_instance(db_info.id, name, flavor_id, flavor.ram, image_id, databases, users, service_type, volume_size) return SimpleInstance(context, db_info, service_status)
def _create_dns_entry(self): LOG.debug("%s: Creating dns entry for instance: %s" % (greenthread.getcurrent(), self.id)) dns_client = create_dns_client(self.context) dns_support = config.Config.get("reddwarf_dns_support", 'False') LOG.debug(_("reddwarf dns support = %s") % dns_support) nova_client = create_nova_client(self.context) if utils.bool_from_string(dns_support): def get_server(): c_id = self.db_info.compute_instance_id return nova_client.servers.get(c_id) def ip_is_available(server): LOG.info("Polling for ip addresses: $%s " % server.addresses) if server.addresses != {}: return True elif server.addresses == {} and\ server.status != InstanceStatus.ERROR: return False elif server.addresses == {} and\ server.status == InstanceStatus.ERROR: LOG.error(_("Instance IP not available, instance (%s): " "server had status (%s).") % (self.id, server.status)) raise ReddwarfError(status=server.status) poll_until(get_server, ip_is_available, sleep_time=1, time_out=60 * 2) server = nova_client.servers.get(self.db_info.compute_instance_id) LOG.info("Creating dns entry...") dns_client.create_instance_entry(self.id, get_ip_address(server.addresses))
def delete_instance(self): try: self.server.delete() except Exception as ex: LOG.error("Error during delete compute server %s " % self.server.id) LOG.error(ex) try: dns_support = config.Config.get("reddwarf_dns_support", "False") LOG.debug(_("reddwarf dns support = %s") % dns_support) if utils.bool_from_string(dns_support): dns_api = create_dns_client(self.context) dns_api.delete_instance_entry(instance_id=self.db_info.id) except Exception as ex: LOG.error("Error during dns entry for instance %s " % self.db_info.id) LOG.error(ex) # Poll until the server is gone. def server_is_finished(): try: server_id = self.db_info.compute_instance_id server = self.nova_client.servers.get(server_id) if server.status not in ["SHUTDOWN", "ACTIVE"]: msg = "Server %s got into ERROR status during delete " "of instance %s!" % (server.id, self.id) LOG.error(msg) return False except nova_exceptions.NotFound: return True poll_until(server_is_finished, sleep_time=2, time_out=int(config.Config.get("server_delete_time_out"))) # If time out occurs, the instance task is stuck in DELETING. LOG.debug("Setting instance %s to deleted..." % self.id) # Delete guest queue. guest = self.get_guest() guest.delete_queue() self.update_db(task_status=InstanceTasks.NONE) self.update_db(deleted=True, deleted_at=datetime.now())
def create(cls, context, name, flavor_id, image_id, databases, users, service_type, volume_size): client = create_nova_client(context) try: flavor = client.flavors.get(flavor_id) except nova_exceptions.NotFound: raise exception.FlavorNotFound(uuid=flavor_id) db_info = DBInstance.create(name=name, flavor_id=flavor_id, tenant_id=context.tenant, volume_size=volume_size, task_status=InstanceTasks.BUILDING) LOG.debug( _("Tenant %s created new Reddwarf instance %s...") % (context.tenant, db_info.id)) service_status = InstanceServiceStatus.create( instance_id=db_info.id, status=ServiceStatuses.NEW) dns_support = config.Config.get("reddwarf_dns_support", 'False') if utils.bool_from_string(dns_support): dns_client = create_dns_client(context) hostname = dns_client.determine_hostname(db_info.id) db_info.hostname = hostname db_info.save() task_api.API(context).create_instance(db_info.id, name, flavor_id, flavor.ram, image_id, databases, users, service_type, volume_size) return SimpleInstance(context, db_info, service_status)
def _create_volume(self, volume_size): LOG.info("Entering create_volume") LOG.debug(_("Starting to create the volume for the instance")) volume_support = config.Config.get("reddwarf_volume_support", 'False') LOG.debug(_("reddwarf volume support = %s") % volume_support) if (volume_size is None or utils.bool_from_string(volume_support) is False): volume_info = { 'block_device': None, 'device_path': None, 'mount_point': None, 'volumes': None, } return volume_info volume_client = create_nova_volume_client(self.context) volume_desc = ("mysql volume for %s" % self.id) volume_ref = volume_client.volumes.create( volume_size, display_name="mysql-%s" % self.id, display_description=volume_desc) # Record the volume ID in case something goes wrong. self.update_db(volume_id=volume_ref.id) utils.poll_until( lambda: volume_client.volumes.get(volume_ref.id), lambda v_ref: v_ref.status in ['available', 'error'], sleep_time=2, time_out=2 * 60) v_ref = volume_client.volumes.get(volume_ref.id) if v_ref.status in ['error']: raise VolumeCreationFailure() LOG.debug(_("Created volume %s") % v_ref) # The mapping is in the format: # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>] # setting the delete_on_terminate instance to true=1 mapping = "%s:%s:%s:%s" % (v_ref.id, '', v_ref.size, 1) bdm = config.Config.get('block_device_mapping', 'vdb') block_device = {bdm: mapping} volumes = [{'id': v_ref.id, 'size': v_ref.size}] LOG.debug("block_device = %s" % block_device) LOG.debug("volume = %s" % volumes) device_path = config.Config.get('device_path', '/dev/vdb') mount_point = config.Config.get('mount_point', '/var/lib/mysql') LOG.debug(_("device_path = %s") % device_path) LOG.debug(_("mount_point = %s") % mount_point) volume_info = {'block_device': block_device, 'device_path': device_path, 'mount_point': mount_point, 'volumes': volumes} return volume_info
def _create_volume(cls, context, db_info, volume_size): volume_support = config.Config.get("reddwarf_volume_support", 'False') LOG.debug(_("reddwarf volume support = %s") % volume_support) if utils.bool_from_string(volume_support): LOG.debug(_("Starting to create the volume for the instance")) volume_client = create_nova_volume_client(context) volume_desc = ("mysql volume for %s" % db_info.id) volume_ref = volume_client.volumes.create( volume_size, display_name="mysql-%s" % db_info.id, display_description=volume_desc) # Record the volume ID in case something goes wrong. db_info.volume_id = volume_ref.id db_info.save() #TODO(cp16net) this is bad to wait here for the volume create # before returning but this was a quick way to get it working # for now we need this to go into the task manager v_ref = volume_client.volumes.get(volume_ref.id) while not v_ref.status in ['available', 'error']: LOG.debug(_("waiting for volume [volume.status=%s]") % v_ref.status) greenthread.sleep(1) v_ref = volume_client.volumes.get(volume_ref.id) if v_ref.status in ['error']: raise rd_exceptions.VolumeCreationFailure() LOG.debug(_("Created volume %s") % v_ref) # The mapping is in the format: # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>] # setting the delete_on_terminate instance to true=1 mapping = "%s:%s:%s:%s" % (v_ref.id, '', v_ref.size, 1) bdm = CONFIG.get('block_device_mapping', 'vdb') block_device = {bdm: mapping} volumes = [{'id': v_ref.id, 'size': v_ref.size}] LOG.debug("block_device = %s" % block_device) LOG.debug("volume = %s" % volumes) device_path = CONFIG.get('device_path', '/dev/vdb') mount_point = CONFIG.get('mount_point', '/var/lib/mysql') LOG.debug(_("device_path = %s") % device_path) LOG.debug(_("mount_point = %s") % mount_point) else: LOG.debug(_("Skipping setting up the volume")) block_device = None device_path = None mount_point = None volumes = None #end volume_support #block_device = "" #device_path = /dev/vdb #mount_point = /var/lib/mysql volume_info = {'block_device': block_device, 'device_path': device_path, 'mount_point': mount_point, 'volumes': volumes} return volume_info
def _create_volume(self, volume_size): LOG.info("Entering create_volume") LOG.debug(_("Starting to create the volume for the instance")) volume_support = config.Config.get("reddwarf_volume_support", 'False') LOG.debug(_("reddwarf volume support = %s") % volume_support) if (volume_size is None or utils.bool_from_string(volume_support) is False): volume_info = { 'block_device': None, 'device_path': None, 'mount_point': None, 'volumes': None, } return volume_info volume_client = create_nova_volume_client(self.context) volume_desc = ("mysql volume for %s" % self.id) volume_ref = volume_client.volumes.create( volume_size, display_name="mysql-%s" % self.id, display_description=volume_desc) # Record the volume ID in case something goes wrong. self.update_db(volume_id=volume_ref.id) utils.poll_until(lambda: volume_client.volumes.get(volume_ref.id), lambda v_ref: v_ref.status in ['available', 'error'], sleep_time=2, time_out=2 * 60) v_ref = volume_client.volumes.get(volume_ref.id) if v_ref.status in ['error']: raise VolumeCreationFailure() LOG.debug(_("Created volume %s") % v_ref) # The mapping is in the format: # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>] # setting the delete_on_terminate instance to true=1 mapping = "%s:%s:%s:%s" % (v_ref.id, '', v_ref.size, 1) bdm = config.Config.get('block_device_mapping', 'vdb') block_device = {bdm: mapping} volumes = [{'id': v_ref.id, 'size': v_ref.size}] LOG.debug("block_device = %s" % block_device) LOG.debug("volume = %s" % volumes) device_path = config.Config.get('device_path', '/dev/vdb') mount_point = config.Config.get('mount_point', '/var/lib/mysql') LOG.debug(_("device_path = %s") % device_path) LOG.debug(_("mount_point = %s") % mount_point) volume_info = { 'block_device': block_device, 'device_path': device_path, 'mount_point': mount_point, 'volumes': volumes } return volume_info
def _create_volume(cls, context, db_info, volume_size): volume_support = config.Config.get("reddwarf_volume_support", 'False') LOG.debug(_("reddwarf volume support = %s") % volume_support) if utils.bool_from_string(volume_support): LOG.debug(_("Starting to create the volume for the instance")) volume_client = create_nova_volume_client(context) volume_desc = ("mysql volume for %s" % db_info.id) volume_ref = volume_client.volumes.create( volume_size, display_name="mysql-%s" % db_info.id, display_description=volume_desc) #TODO(cp16net) this is bad to wait here for the volume create # before returning but this was a quick way to get it working # for now we need this to go into the task manager v_ref = volume_client.volumes.get(volume_ref.id) while not v_ref.status in ['available', 'error']: LOG.debug(_("waiting for volume [volume.status=%s]") % v_ref.status) greenthread.sleep(1) v_ref = volume_client.volumes.get(volume_ref.id) if v_ref.status in ['error']: raise rd_exceptions.ReddwarfError( _("Could not create volume")) LOG.debug(_("Created volume %s") % v_ref) # The mapping is in the format: # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>] # setting the delete_on_terminate instance to true=1 mapping = "%s:%s:%s:%s" % (v_ref.id, '', v_ref.size, 1) # TODO(rnirmal) This mapping device needs to be configurable. # and we may have to do a little more trickery here. # We don't know what's the next device available on the # guest. Also in cases for ovz where this is mounted on # the host, that's not going to work for us. block_device = {'vdb': mapping} volume = [{'id': v_ref.id, 'size': v_ref.size}] LOG.debug("block_device = %s" % block_device) LOG.debug("volume = %s" % volume) device_path = CONFIG.get('device_path') mount_point = CONFIG.get('mount_point') LOG.debug(_("device_path = %s") % device_path) LOG.debug(_("mount_point = %s") % mount_point) else: LOG.debug(_("Skipping setting up the volume")) block_device = None device_path = None mount_point = None volume = None #end volume_support volume_info = {'block_device': block_device, 'device_path': device_path, 'mount_point': mount_point} return volume, volume_info
def _try_attach_volume(self, context, body, credential, region, volume_size, instance): volume_support = CONFIG.get('reddwarf_volume_support', 'False') if not utils.bool_from_string(volume_support): # Do nothing if volume-support is not enabled return # Create the remote volume and a DB Volume record try: volume = models.Volume.create(credential, region, volume_size, 'mysql-%s' % instance['remote_id']).data() except Exception as e: LOG.exception("Failed to create a remote volume of size %s" % volume_size) raise exception.VolumeCreationFailure(e) else: LOG.debug("Created remote volume %s of size %s" % (volume['id'], volume_size)) try: db_volume = models.DBVolume().create(volume_id=volume['id'], size=volume_size, availability_zone=region, instance_id="TBD", tenant_id=context.tenant) except Exception as e: LOG.exception("Failed to write DB Volume record for instance volume") raise exception.ReddwarfError(e) # Attempt to attach the volume to an instance try: device_name = config.Config.get('volume_device_name', '/dev/vdc') models.Volume.attach(credential, region, volume, instance['remote_id'], device_name) except Exception as e: LOG.exception("Failed to attach volume %s with instance remote_id %s" % (volume['id'], instance['remote_id'])) # Failed to attach the volume delete the volume try: models.Volume.delete(credential, region, volume['id']) except exception.NotFound as e: # volume not found, ok pass except exception.ReddwarfError as e: LOG.exception("Failed to delete volume after attachment failure") else: # Delete the DB volume record as well db_volume.delete() raise exception.VolumeAttachmentFailure(e) else: LOG.debug("Attached volume %s to instance %s" % (volume['id'], instance['remote_id'])) try: db_volume.update(instance_id=instance['id']) except Exception as e: LOG.exception("Failed to update DB Volume with instance id") raise exception.ReddwarfError(e)
def _create_volume(self, volume_size): LOG.info("Entering create_volume") LOG.debug(_("Starting to create the volume for the instance")) volume_support = config.Config.get("reddwarf_volume_support", "False") LOG.debug(_("reddwarf volume support = %s") % volume_support) if volume_size is None or utils.bool_from_string(volume_support) is False: volume_info = {"block_device": None, "device_path": None, "mount_point": None, "volumes": None} return volume_info volume_client = create_nova_volume_client(self.context) volume_desc = "mysql volume for %s" % self.id volume_ref = volume_client.volumes.create( volume_size, display_name="mysql-%s" % self.id, display_description=volume_desc ) # Record the volume ID in case something goes wrong. self.update_db(volume_id=volume_ref.id) utils.poll_until( lambda: volume_client.volumes.get(volume_ref.id), lambda v_ref: v_ref.status in ["available", "error"], sleep_time=2, time_out=2 * 60, ) v_ref = volume_client.volumes.get(volume_ref.id) if v_ref.status in ["error"]: raise VolumeCreationFailure() LOG.debug(_("Created volume %s") % v_ref) # The mapping is in the format: # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>] # setting the delete_on_terminate instance to true=1 mapping = "%s:%s:%s:%s" % (v_ref.id, "", v_ref.size, 1) bdm = config.Config.get("block_device_mapping", "vdb") block_device = {bdm: mapping} volumes = [{"id": v_ref.id, "size": v_ref.size}] LOG.debug("block_device = %s" % block_device) LOG.debug("volume = %s" % volumes) device_path = config.Config.get("device_path", "/dev/vdb") mount_point = config.Config.get("mount_point", "/var/lib/mysql") LOG.debug(_("device_path = %s") % device_path) LOG.debug(_("mount_point = %s") % mount_point) volume_info = { "block_device": block_device, "device_path": device_path, "mount_point": mount_point, "volumes": volumes, } return volume_info
def update_hostname(self, instance): """ Create the hostname field based on the instance id. Use instance by default """ dns_support = config.Config.get('reddwarf_dns_support', 'False') if utils.bool_from_string(dns_support): entry = self.entry_factory.create_entry(instance.id) instance.hostname = entry.name instance.save() else: instance.hostname = instance.name instance.save()
def create(self, req, body, tenant_id): """Creates a snapshot.""" LOG.debug("Snapshots.create() called with %s, %s" % (tenant_id, id)) LOG.info("Creating a database snapshot for tenant '%s'" % tenant_id) LOG.info("req : '%s'\n\n" % req) LOG.info("body : '%s'\n\n" % body) snapshot_support = CONFIG.get('reddwarf_snapshot_support', True) if not utils.bool_from_string(snapshot_support): raise exception.NotImplemented("This resource is temporarily not available") # Return if instance is not running try: instance_id = body['snapshot']['instanceId'] except exception.ReddwarfError, e: LOG.exception("body['snapshot']['instanceId'] does not exist") return wsgi.Result(errors.wrap(errors.Snapshot.NO_BODY_INSTANCE_ID))
def delete(self, force=False): if not force and self.server.status in SERVER_INVALID_ACTION_STATUSES: raise rd_exceptions.UnprocessableEntity("Instance %s is not ready." % self.id) LOG.debug(_(" ... deleting compute id = %s") % self.server.id) self._delete_server() LOG.debug(_(" ... setting status to DELETING.")) self.db_info.task_status = InstanceTasks.DELETING self.db_info.save() #TODO(tim.simpson): Put this in the task manager somehow to shepard # deletion? dns_support = config.Config.get("reddwarf_dns_support", 'False') LOG.debug(_("reddwarf dns support = %s") % dns_support) if utils.bool_from_string(dns_support): dns_client = create_dns_client(self.context) dns_client.delete_instance_entry(instance_id=self.db_info['id'])
def data(self): ip = get_ip_address(self.instance.addresses) volumes = get_volumes(self.instance.volumes) instance_dict = { "id": self.instance.id, "name": self.instance.name, "status": self.instance.status, "links": self._build_links(), } dns_support = config.Config.get("reddwarf_dns_support", "False") if utils.bool_from_string(dns_support): instance_dict["hostname"] = self.instance.db_info.hostname if self.add_addresses and ip is not None and len(ip) > 0: instance_dict["ip"] = ip if self.add_volumes and volumes is not None: instance_dict["volume"] = volumes LOG.debug(instance_dict) return {"instance": instance_dict}
def data(self): result = super(InstanceDetailView, self).data() result['instance']['created'] = self.instance.created result['instance']['updated'] = self.instance.updated dns_support = config.Config.get("reddwarf_dns_support", 'False') if utils.bool_from_string(dns_support): result['instance']['hostname'] = self.instance.hostname if self.add_addresses: ip = get_ip_address(self.instance.addresses) if ip is not None and len(ip) > 0: result['instance']['ip'] = ip if self.add_volumes: if (isinstance(self.instance, models.DetailInstance) and self.instance.volume_used): used = self._to_gb(self.instance.volume_used) result['instance']['volume']['used'] = used return result
def data(self): result = super(InstanceDetailView, self).data() result['instance']['created'] = self.instance.created result['instance']['updated'] = self.instance.updated dns_support = config.Config.get("reddwarf_dns_support", 'False') if utils.bool_from_string(dns_support): result['instance']['hostname'] = self.instance.hostname if self.add_addresses: ip = get_ip_address(self.instance.addresses) if ip is not None and len(ip) > 0: result['instance']['ip'] = ip if self.add_volumes: if isinstance(self.instance, models.DetailInstance) and \ self.instance.volume_used: used = self._to_gb(self.instance.volume_used) result['instance']['volume']['used'] = used return result
def load_volumes(context, server_id, client=None): volume_support = config.Config.get("reddwarf_volume_support", 'False') if utils.bool_from_string(volume_support): if client is None: client = create_nova_client(context) volume_client = create_nova_volume_client(context) try: volumes = [] volumes_info = client.volumes.get_server_volumes(server_id) volume_ids = [attachments.volumeId for attachments in volumes_info] for volume_id in volume_ids: volume_info = volume_client.volumes.get(volume_id) volume = {'id': volume_info.id, 'size': volume_info.size} volumes.append(volume) except nova_exceptions.NotFound, e: LOG.debug("Could not find nova server_id(%s)" % server_id) raise rd_exceptions.VolumeAttachmentsNotFound(server_id=server_id) except nova_exceptions.ClientException, e: raise rd_exceptions.ReddwarfError(str(e))
def _create_dns_entry(self): LOG.debug("%s: Creating dns entry for instance: %s" % (greenthread.getcurrent(), self.id)) dns_client = create_dns_client(self.context) dns_support = config.Config.get("reddwarf_dns_support", 'False') LOG.debug(_("reddwarf dns support = %s") % dns_support) nova_client = create_nova_client(self.context) if utils.bool_from_string(dns_support): def get_server(): c_id = self.db_info.compute_instance_id return nova_client.servers.get(c_id) def ip_is_available(server): LOG.info("Polling for ip addresses: $%s " % server.addresses) if server.addresses != {}: return True elif (server.addresses == {} and server.status != InstanceStatus.ERROR): return False elif (server.addresses == {} and server.status == InstanceStatus.ERROR): msg = _("Instance IP not available, instance (%s): " "server had status (%s).") LOG.error(msg % (self.id, server.status)) raise ReddwarfError(status=server.status) poll_until(get_server, ip_is_available, sleep_time=1, time_out=60 * 2) server = nova_client.servers.get(self.db_info.compute_instance_id) LOG.info("Creating dns entry...") dns_client.create_instance_entry(self.id, get_ip_address(server.addresses))
def __init__(self): self.add_addresses = utils.bool_from_string( config.Config.get('add_addresses', 'False')) self.add_volumes = utils.bool_from_string( config.Config.get('reddwarf_volume_support', 'False'))
def create(cls, context, name, flavor_ref, image_id, databases, service_type, volume_size): db_info = DBInstance.create(name=name, task_status=InstanceTasks.NONE) LOG.debug(_("Created new Reddwarf instance %s...") % db_info.id) if volume_size: volume_info = cls._create_volume(context, db_info, volume_size) block_device_mapping = volume_info['block_device'] device_path = volume_info['device_path'] mount_point = volume_info['mount_point'] volumes = volume_info['volumes'] else: block_device_mapping = None device_path = None mount_point = None volumes = [] client = create_nova_client(context) files = {"/etc/guest_info": "guest_id=%s\nservice_type=%s\n" % (db_info.id, service_type)} server = client.servers.create(name, image_id, flavor_ref, files=files, block_device_mapping=block_device_mapping) LOG.debug(_("Created new compute instance %s.") % server.id) db_info.compute_instance_id = server.id db_info.save() service_status = InstanceServiceStatus.create(instance_id=db_info.id, status=ServiceStatuses.NEW) # Now wait for the response from the create to do additional work guest = create_guest_client(context, db_info.id) # populate the databases model_schemas = populate_databases(databases) guest.prepare(512, model_schemas, users=[], device_path=device_path, mount_point=mount_point) dns_support = config.Config.get("reddwarf_dns_support", 'False') LOG.debug(_("reddwarf dns support = %s") % dns_support) dns_client = create_dns_client(context) # Default the hostname to instance name if no dns support dns_client.update_hostname(db_info) if utils.bool_from_string(dns_support): def get_server(): return client.servers.get(server.id) def ip_is_available(server): if server.addresses != {}: return True elif server.addresses == {} and\ server.status != InstanceStatus.ERROR: return False elif server.addresses == {} and\ server.status == InstanceStatus.ERROR: LOG.error(_("Instance IP not available, instance (%s): server had " " status (%s).") % (db_info['id'], server.status)) raise rd_exceptions.ReddwarfError( status=server.status) poll_until(get_server, ip_is_available, sleep_time=1, time_out=60*2) dns_client.create_instance_entry(db_info['id'], get_ip_address(server.addresses)) return Instance(context, db_info, server, service_status, volumes)
LOG.info("body : '%s'\n\n" % body) context = rd_context.ReddwarfContext( auth_tok=req.headers["X-Auth-Token"], tenant=tenant_id) try: num_instances = self._check_instance_quota(context, 1) except exception.QuotaError, e: LOG.exception("Quota Error encountered for tenant %s" % tenant_id) maximum_instances_allowed = quota.get_tenant_quotas(context, context.tenant)['instances'] return wsgi.Result(errors.wrap(errors.Instance.QUOTA_EXCEEDED, "You are only allowed to create %s instances on you account." % maximum_instances_allowed), 413) # Extract any snapshot info from the request snapshot = None snapshot_support = CONFIG.get('reddwarf_snapshot_support', True) if utils.bool_from_string(snapshot_support): try: snapshot = self._extract_snapshot(body, tenant_id) except exception.ReddwarfError, e: LOG.exception("Error creating new instance") return wsgi.Result(errors.wrap(errors.Snapshot.NOT_FOUND), 500) except Exception, e: LOG.exception("Error creating new instance") return wsgi.Result(errors.wrap(errors.Instance.MALFORMED_BODY), 500) # Extract volume size info from the request and check Quota try: volume_size = self._extract_volume_size(body) if volume_size is None: volume_size = config.Config.get('default_volume_size', 20)