Exemplo n.º 1
0
        def create(rsrc_id, rsrc, count=1, created_by=None):
            """Create (configure) instance."""
            _LOGGER.info('create: count = %s, %s %r, created_by = %s', count,
                         rsrc_id, rsrc, created_by)

            admin_app = admin.Application(context.GLOBAL.ldap.conn)
            if not rsrc:
                configured = admin_app.get(rsrc_id)
            else:
                # Make sure defaults are present
                configured = admin_app.from_entry(admin_app.to_entry(rsrc))
                app.verify_feature(rsrc.get('features', []))

            if 'services' in configured and not configured['services']:
                del configured['services']
            if '_id' in configured:
                del configured['_id']

            _LOGGER.info('Configured: %s %r', rsrc_id, configured)

            _validate(configured)

            self.plugins = _api_plugins(self.plugins)
            for plugin in self.plugins:
                configured = plugin.add_attributes(rsrc_id, configured)

            _check_required_attributes(configured)
            _set_defaults(configured, rsrc_id)

            scheduled = masterapi.create_apps(context.GLOBAL.zk.conn, rsrc_id,
                                              configured, count, created_by)
            return scheduled
Exemplo n.º 2
0
        def create(rsrc_id, rsrc, count=1):
            """Create (configure) instance."""
            _LOGGER.info('create: count = %s, %s %r', count, rsrc_id, rsrc)

            if not rsrc:
                admin_app = admin.Application(context.GLOBAL.ldap.conn)
                configured = admin_app.get(rsrc_id)
            else:
                configured = rsrc
                app.verify_feature(rsrc.get('features', []))

            if '_id' in configured:
                del configured['_id']

            _validate(configured)

            if instance_plugin:
                configured = instance_plugin.add_attributes(
                    rsrc_id, configured)
            if 'proid' not in configured:
                raise Exception('Missing required attribute: proid')
            if 'environment' not in configured:
                raise Exception('Missing required attribute: environment')

            if 'identity_group' not in configured:
                configured['identity_group'] = None

            scheduled = master.create_apps(context.GLOBAL.zk.conn, rsrc_id,
                                           configured, count)
            return scheduled
Exemplo n.º 3
0
        def create(rsrc_id, rsrc, count=1, created_by=None):
            """Create (configure) instance."""
            _LOGGER.info('create: count = %s, %s %r, created_by = %s', count,
                         rsrc_id, rsrc, created_by)

            # Check scheduled quota.
            zkclient = context.GLOBAL.zk.conn
            scheduled_stats = masterapi.get_scheduled_stats(zkclient)

            total_apps = sum(scheduled_stats.values())
            if total_apps + count > _TOTAL_SCHEDULED_QUOTA:
                raise exc.QuotaExceededError(
                    'Total scheduled apps quota exceeded.')

            proid_apps = scheduled_stats.get(rsrc_id[:rsrc_id.find('.')], 0)
            if proid_apps + count > _PROID_SCHEDULED_QUOTA:
                raise exc.QuotaExceededError(
                    'Proid scheduled apps quota exceeded.')

            admin_app = admin.Application(context.GLOBAL.ldap.conn)
            if not rsrc:
                configured = admin_app.get(rsrc_id)
            else:
                # Make sure defaults are present
                configured = admin_app.from_entry(admin_app.to_entry(rsrc))
                app.verify_feature(rsrc.get('features', []))

            if 'services' in configured and not configured['services']:
                del configured['services']
            if '_id' in configured:
                del configured['_id']

            _LOGGER.info('Configured: %s %r', rsrc_id, configured)

            _validate(configured)

            self.plugins = _api_plugins(self.plugins)
            for plugin in self.plugins:
                configured = plugin.add_attributes(rsrc_id, configured)

            _check_required_attributes(configured)
            _set_defaults(configured, rsrc_id)

            scheduled = masterapi.create_apps(zkclient, rsrc_id, configured,
                                              count, created_by)
            return scheduled
Exemplo n.º 4
0
        def create(rsrc_id, rsrc, count=1):
            """Create (configure) instance."""
            _LOGGER.info('create: count = %s, %s %r', count, rsrc_id, rsrc)

            admin_app = admin.Application(context.GLOBAL.ldap.conn)
            if not rsrc:
                configured = admin_app.get(rsrc_id)
                _LOGGER.info('Configured: %s %r', rsrc_id, configured)
            else:
                # Make sure defaults are present
                configured = admin_app.from_entry(admin_app.to_entry(rsrc))
                app.verify_feature(rsrc.get('features', []))

            if '_id' in configured:
                del configured['_id']

            _validate(configured)

            if instance_plugin:
                configured = instance_plugin.add_attributes(
                    rsrc_id, configured)

            if 'proid' not in configured:
                raise exc.TreadmillError('Missing required attribute: proid')
            if 'environment' not in configured:
                raise exc.TreadmillError(
                    'Missing required attribute: environment')

            if 'identity_group' not in configured:
                configured['identity_group'] = None

            if 'affinity' not in configured:
                configured['affinity'] = '{0}.{1}'.format(*rsrc_id.split('.'))

            scheduled = master.create_apps(context.GLOBAL.zk.conn, rsrc_id,
                                           configured, count)
            return scheduled
Exemplo n.º 5
0
        def create(rsrc_id, rsrc, count=1, created_by=None,
                   debug=False, debug_services=None):
            """Create (configure) instance."""
            _LOGGER.info('create: count = %s, %s %r, created_by = %s',
                         count, rsrc_id, rsrc, created_by)

            # Check scheduled quota.
            zkclient = context.GLOBAL.zk.conn
            scheduled_stats = masterapi.get_scheduled_stats(zkclient)
            if not scheduled_stats:
                scheduled_stats = {}

            total_apps = sum(scheduled_stats.values())
            if total_apps + count > _TOTAL_SCHEDULED_QUOTA:
                raise exc.QuotaExceededError(
                    'Total scheduled apps quota exceeded.')

            proid_apps = scheduled_stats.get(rsrc_id[:rsrc_id.find('.')], 0)
            if proid_apps + count > _PROID_SCHEDULED_QUOTA:
                raise exc.QuotaExceededError(
                    'Proid scheduled apps quota exceeded.')

            admin_app = context.GLOBAL.admin.application()
            if not rsrc:
                configured = admin_app.get(rsrc_id)
            else:
                # Make sure defaults are present
                configured = admin_app.from_entry(admin_app.to_entry(rsrc))
                app.verify_feature(rsrc.get('features', []))

            if 'services' in configured and not configured['services']:
                del configured['services']
            if '_id' in configured:
                del configured['_id']

            _LOGGER.info('Configured: %s %r', rsrc_id, configured)

            _validate(configured)

            for plugin in self._plugins:
                configured = plugin.add_attributes(rsrc_id, configured)

            _check_required_attributes(configured)
            _set_defaults(configured, rsrc_id)

            services = {
                service['name']: service
                for service in configured.get('services', [])
            }

            if not debug_services:
                debug_services = list(services) if debug else []

            for service in debug_services:
                if service in services:
                    services[service]['downed'] = True
                    _LOGGER.info('Configuring service %s as down', service)
                else:
                    raise exc.InvalidInputError(
                        __name__, 'Invalid service %s' % service
                    )

            scheduled = masterapi.create_apps(
                zkclient, rsrc_id, configured, count, created_by
            )
            return scheduled