Ejemplo n.º 1
0
 def test_delete(self):
     site = {'site_id': 'test_site_uuid',
             'site_name': 'test_site',
             'az_id': 'test_az_uuid'}
     models.create_site(self.context, site)
     models.delete_site(self.context, 'test_site_uuid')
     self.assertRaises(exception.ResourceNotFound, models.get_site,
                       self.context, 'test_site_uuid')
Ejemplo n.º 2
0
    def post(self, **kw):
        context = _extract_context_from_environ(_get_environment())
        if not context.is_admin:
            pecan.abort(400, 'Admin role required to create sites')
            return

        site_name = kw.get('name')
        is_top_site = kw.get('top', False)

        if not site_name:
            pecan.abort(400, 'Name of site required')
            return

        site_filters = [{
            'key': 'site_name',
            'comparator': 'eq',
            'value': site_name
        }]
        sites = models.list_sites(context, site_filters)
        if sites:
            pecan.abort(409, 'Site with name %s exists' % site_name)
            return

        ag_name = 'ag_%s' % site_name
        # top site doesn't need az
        az_name = 'az_%s' % site_name if not is_top_site else ''

        try:
            site_dict = {
                'site_id': str(uuid.uuid4()),
                'site_name': site_name,
                'az_id': az_name
            }
            site = models.create_site(context, site_dict)
        except Exception as e:
            LOG.debug(e.message)
            pecan.abort(500, 'Fail to create site')
            return

        # top site doesn't need aggregate
        if is_top_site:
            pecan.response.status = 201
            return {'site': site}
        else:
            try:
                top_client = client.Client()
                top_client.create_aggregates(context, ag_name, az_name)
            except Exception as e:
                LOG.debug(e.message)
                # delete previously created site
                models.delete_site(context, site['site_id'])
                pecan.abort(500, 'Fail to create aggregate')
                return
            pecan.response.status = 201
            return {'site': site}
Ejemplo n.º 3
0
    def post(self, **kw):
        context = _extract_context_from_environ(_get_environment())
        if not context.is_admin:
            pecan.abort(400, 'Admin role required to create sites')
            return

        site_name = kw.get('name')
        is_top_site = kw.get('top', False)

        if not site_name:
            pecan.abort(400, 'Name of site required')
            return

        site_filters = [{'key': 'site_name', 'comparator': 'eq',
                         'value': site_name}]
        sites = models.list_sites(context, site_filters)
        if sites:
            pecan.abort(409, 'Site with name %s exists' % site_name)
            return

        ag_name = utils.get_ag_name(site_name)
        # top site doesn't need az
        az_name = utils.get_az_name(site_name) if not is_top_site else ''

        try:
            site_dict = {'site_id': str(uuid.uuid4()),
                         'site_name': site_name,
                         'az_id': az_name}
            site = models.create_site(context, site_dict)
        except Exception as e:
            LOG.debug(e.message)
            pecan.abort(500, 'Fail to create site')
            return

        # top site doesn't need aggregate
        if is_top_site:
            pecan.response.status = 201
            return {'site': site}
        else:
            try:
                top_client = client.Client()
                top_client.create_aggregates(context, ag_name, az_name)
                site_api = cascading_site_api.CascadingSiteNotifyAPI()
                site_api.create_site(context, site_name)
            except Exception as e:
                LOG.debug(e.message)
                # delete previously created site
                models.delete_site(context, site['site_id'])
                pecan.abort(500, 'Fail to create aggregate')
                return
            pecan.response.status = 201
            return {'site': site}