Exemple #1
0
def validate_instance_nics(context, instances):
    """Checking networks are same for the cluster."""
    instance_nics = []
    for instance in instances:
        nics = instance.get('nics')
        if nics:
            instance_nics.append(nics[0].get('net-id'))
    if len(set(instance_nics)) > 1:
        raise exception.ClusterNetworksNotEqual()
    if not instance_nics:
        return
    instance_nic = instance_nics[0]
    try:
        neutron_client = remote.create_neutron_client(context)
        neutron_client.find_resource('network', instance_nic)
    except neutron_exceptions.NotFound:
        raise exception.NetworkNotFound(uuid=instance_nic)
Exemple #2
0
def get_management_networks(context):
    """Cache the management network names.

    When CONF.default_neutron_networks is changed, the Trove service needs to
    restart so the global cache will be refreshed.
    """
    global MGMT_NETWORKS

    if MGMT_NETWORKS is not None:
        return MGMT_NETWORKS

    MGMT_NETWORKS = []
    if len(CONF.default_neutron_networks) > 0:
        neutron_client = remote.create_neutron_client(context)

        for net_id in CONF.default_neutron_networks:
            MGMT_NETWORKS.append(
                neutron_client.show_network(net_id)['network']['name'])

    return MGMT_NETWORKS
Exemple #3
0
 def __init__(self, context):
     try:
         self.client = remote.create_neutron_client(context)
     except neutron_exceptions.NeutronClientException as e:
         raise exception.TroveError(str(e))
 def __init__(self, context, region_name):
     try:
         self.client = remote.create_neutron_client(context, region_name)
     except neutron_exceptions.NeutronClientException as e:
         raise exception.TroveError(str(e))
Exemple #5
0
    def create(self, req, body, tenant_id):
        # TODO(hub-cap): turn this into middleware
        LOG.info(_LI("Creating a database instance for tenant '%s'"),
                 tenant_id)
        LOG.debug("req : '%s'\n\n", strutils.mask_password(req))
        LOG.debug("body : '%s'\n\n", strutils.mask_password(body))
        context = req.environ[wsgi.CONTEXT_KEY]
        datastore_args = body['instance'].get('datastore', {})
        datastore, datastore_version = (
            datastore_models.get_datastore_version(**datastore_args))
        image_id = datastore_version.image_id
        name = body['instance']['name']
        flavor_ref = body['instance']['flavorRef']
        flavor_id = utils.get_id_from_href(flavor_ref)

        configuration = self._configuration_parse(context, body)
        databases = populate_validated_databases(
            body['instance'].get('databases', []))
        database_names = [database.get('_name', '') for database in databases]
        users = None
        try:
            users = populate_users(body['instance'].get('users', []),
                                   database_names)
        except ValueError as ve:
            raise exception.BadRequest(msg=ve)

        if 'volume' in body['instance']:
            volume_size = int(body['instance']['volume']['size'])
        else:
            volume_size = None

        if 'restorePoint' in body['instance']:
            backupRef = body['instance']['restorePoint']['backupRef']
            backup_id = utils.get_id_from_href(backupRef)
        else:
            backup_id = None

        availability_zone = body['instance'].get('availability_zone')
        nics = body['instance'].get('nics')
        #rds-start
        if CONF.private_network:
            from trove.common.remote import create_neutron_client
            from neutronclient.common import exceptions as neutron_exceptions
            client = create_neutron_client(context)
            try:
                net_info = client.list_networks(name=CONF.private_network)
                private_id = net_info['networks'][0]['id']
            except neutron_exceptions.NotFound:
                raise neutron_exceptions.NotFound((_("failed geting private"
                                                     " net id for: %s") %
                                                     CONF.private_network))
            else:
                nics.insert(1,{'net-id': private_id})
                LOG.info(_("attach network is %s") % nics)
        #rds-end
			

        slave_of_id = body['instance'].get('replica_of',
                                           # also check for older name
                                           body['instance'].get('slave_of'))
        replica_count = body['instance'].get('replica_count')
        instance = models.Instance.create(context, name, flavor_id,
                                          image_id, databases, users,
                                          datastore, datastore_version,
                                          volume_size, backup_id,
                                          availability_zone, nics,
                                          configuration, slave_of_id,
                                          replica_count=replica_count)

        view = views.InstanceDetailView(instance, req=req)
        return wsgi.Result(view.data(), 200)