Upload RabbitMQ environment configuration from a template.
182253
def upload_rabbitmq_environment_conf(template_name=None, context=None, restart=True):
    """"""
    
    template_name = template_name or u'rabbitmq/rabbitmq-env.conf'
    destination = u'/etc/rabbitmq/rabbitmq-env.conf'
    upload_template(template_name, destination, context=context, use_sudo=True)
    if restart:
        restart_service(u'rabbitmq')
561123
def call(format: config.default_format, context: config.default_context, **input)
      ensure_config

      env = self.class.render_env(format: format, context: context)
      template_env = self.class.template_env(format: format, context: context)

      locals = locals(template_env, input)
      output = env.template(config.template, template_env.scope(config.scope, locals))

      if layout?
        layout_env = self.class.layout_env(format: format, context: context)
        output = env.template(self.class.layout_path, layout_env.scope(config.scope, layout_locals(locals))) { output }
      end

      Rendered.new(output: output, locals: locals)
    end
705586
def _render_config(cls, dest, template_name, template_args):
        
        template_args = template_args.copy()

        # Substitute values here
        pyversion = template_args['pyversion']
        template_args['pyversion'] = cls.PYVERSIONS[pyversion]

        template = template_env.get_template(template_name)
        contents = template.render(**template_args)
        _write_file(dest, contents)
541599
def deploy(environment, zappa_settings):
    
    print(("Deploying " + environment))

    zappa, settings, lambda_name, zip_path = \
        _package(environment, zappa_settings)

    s3_bucket_name = settings['s3_bucket']

    try:
        # Load your AWS credentials from ~/.aws/credentials
        zappa.load_credentials()

        # Make sure the necessary IAM execution roles are available
        zappa.create_iam_roles()

        # Upload it to S3
        zip_arn = zappa.upload_to_s3(zip_path, s3_bucket_name)

        # Register the Lambda function with that zip as the source
        # You'll also need to define the path to your lambda_handler code.
        lambda_arn = zappa.create_lambda_function(bucket=s3_bucket_name,
                                                  s3_key=zip_path,
                                                  function_name=lambda_name,
                                                  handler='handler.lambda_handler',
                                                  vpc_config=settings['vpc_config'],
                                                  memory_size=settings['memory_size'])

        # Create and configure the API Gateway
        api_id = zappa.create_api_gateway_routes(lambda_arn, lambda_name)

        # Deploy the API!
        endpoint_url = zappa.deploy_api_gateway(api_id, environment)

        # Remove the uploaded zip from S3, because it is now registered..
        zappa.remove_from_s3(zip_path, s3_bucket_name)

        if settings['touch']:
            requests.get(endpoint_url)
    finally:
        try:
            # Finally, delete the local copy our zip package
            if settings['delete_zip']:
                os.remove(zip_path)
        except:
            print("WARNING: Manual cleanup of the zip might be needed.")

    print(("Your Zappa deployment is live!: " + endpoint_url))
1017851
def setup(self):
        """"""
        self.template = self._generate_inline_policy()
        if self.dry_run is not True:
            self.client = self._get_client()
            username = self._get_username_for_key()
            policy_document = self._generate_inline_policy()
            self._attach_inline_policy(username, policy_document)
            pass
334848
def init(self):
        """"""
        if not self.export_enable:
            return None
        try:
            parameters = pika.URLParameters(
                'amqp://' + self.user +
                ':' + self.password +
                '@' + self.host +
                ':' + self.port + '/')
            connection = pika.BlockingConnection(parameters)
            channel = connection.channel()
            return channel
        except Exception as e:
            logger.critical("Connection to rabbitMQ failed : %s " % e)
            return None
609711
public static void configureFactory( ConnectionFactory factory, Map<String,String> configuration )
	throws IOException {

		final Logger logger = Logger.getLogger( RabbitMqUtils.class.getName());
		logger.fine( "Configuring a connection factory for RabbitMQ." );

		String messageServerIp = configuration.get( RABBITMQ_SERVER_IP );
		if( messageServerIp != null ) {
			Map.Entry<String,Integer> entry = Utils.findUrlAndPort( messageServerIp );
			factory.setHost( entry.getKey());
			if( entry.getValue() > 0 )
				factory.setPort( entry.getValue());
		}

		factory.setUsername( configuration.get( RABBITMQ_SERVER_USERNAME ));
		factory.setPassword( configuration.get( RABBITMQ_SERVER_PASSWORD ));

		// Timeout for connection establishment: 5s
		factory.setConnectionTimeout( 5000 );

		// Configure automatic reconnection
		factory.setAutomaticRecoveryEnabled( true );

		// Recovery interval: 10s
		factory.setNetworkRecoveryInterval( 10000 );

		// Exchanges and so on should be redeclared if necessary
		factory.setTopologyRecoveryEnabled( true );

		// SSL
		if( Boolean.parseBoolean( configuration.get( RABBITMQ_USE_SSL ))) {
			logger.fine( "Connection factory for RabbitMQ: SSL is used." );

			InputStream clientIS = null;
			InputStream storeIS = null;
			try {
				clientIS = new FileInputStream( configuration.get( RABBITMQ_SSL_KEY_STORE_PATH ));
				storeIS = new FileInputStream( configuration.get( RABBITMQ_SSL_TRUST_STORE_PATH ));

				char[] keyStorePassphrase = configuration.get( RABBITMQ_SSL_KEY_STORE_PASSPHRASE ).toCharArray();
				KeyStore ks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_KEY_STORE_TYPE, DEFAULT_SSL_KEY_STORE_TYPE ));
				ks.load( clientIS, keyStorePassphrase );

				String value = getValue( configuration, RABBITMQ_SSL_KEY_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY );
				KeyManagerFactory kmf = KeyManagerFactory.getInstance( value );
				kmf.init( ks, keyStorePassphrase );

				char[] trustStorePassphrase = configuration.get( RABBITMQ_SSL_TRUST_STORE_PASSPHRASE ).toCharArray();
				KeyStore tks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_TRUST_STORE_TYPE, DEFAULT_SSL_TRUST_STORE_TYPE ));
				tks.load( storeIS, trustStorePassphrase );

				value = getValue( configuration, RABBITMQ_SSL_TRUST_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY );
				TrustManagerFactory tmf = TrustManagerFactory.getInstance( value );
				tmf.init( tks );

				SSLContext c = SSLContext.getInstance( getValue( configuration, RABBITMQ_SSL_PROTOCOL, DEFAULT_SSL_PROTOCOL ));
				c.init( kmf.getKeyManagers(), tmf.getTrustManagers(), null );
				factory.useSslProtocol( c );

			} catch( GeneralSecurityException e ) {
				throw new IOException( "SSL configuration for the RabbitMQ factory failed.", e );

			} finally {
				Utils.closeQuietly( storeIS );
				Utils.closeQuietly( clientIS );
			}
		}
	}
404620
def create_from_config(self, config):
        

        configService = ConfigService()
        template = TemplateService()

        template.output = config["output"]["location"]

        template_file = configService.get_template_from_config(config)
        template.input = os.path.basename(template_file)
        template.env = Environment(loader=FileSystemLoader(os.path.dirname(template_file)))

        return template
266465
def main(argv=None):
    """"""
    arguments = cli_common(__doc__, argv=argv)
    plugin = 'benchmark' if arguments['benchmark'] else None

    if arguments['-g']:
        template.generate_config(plugin, arguments['<FILE>'])
    else:
        with open(arguments['<FILE>']) as istr:
            context = json.load(istr)
        kwargs = dict(no_input=True, extra_context=context)
        if arguments['--output-dir']:
            kwargs.update(output_dir=arguments['--output-dir'])
        if arguments['--interactive']:
            kwargs.update(no_input=False)
        logging.info(
            'generating template in directory ' + kwargs.get('output_dir', os.getcwd())
        )
        template.generate_template(plugin, **kwargs)
639244
def _rabbitmq_config(self):
        
        config = self.application.settings.get('rabbitmq')
        if not config:
            raise exceptions.ConfigurationException('rabbitmq')
        return config
162770
def set_env_from_args(args):
    ''' 
    '''
    args = vars(args)

    if args.get('apiserver_host') is not None:
        config['DX_APISERVER_HOST'] = args['apiserver_host']
    if args.get('apiserver_port') is not None:
        config['DX_APISERVER_PORT'] = args['apiserver_port']
    if args.get('apiserver_protocol') is not None:
        config['DX_APISERVER_PROTOCOL'] = args['apiserver_protocol']
    if args.get('project_context_id') is not None:
        config['DX_PROJECT_CONTEXT_ID'] = args['project_context_id']
    if args.get('workspace_id') is not None:
        config['DX_WORKSPACE_ID'] = args['workspace_id']
    if args.get('cli_wd') is not None:
        config['DX_CLI_WD'] = args['cli_wd']
    if args.get('security_context') is not None:
        config['DX_SECURITY_CONTEXT'] = args['security_context']
    if args.get('auth_token') is not None:
        config['DX_SECURITY_CONTEXT'] = json.dumps({"auth_token": args['auth_token'],
                                                    "auth_token_type": "Bearer"})
1027120
private RabbitTemplate getRabbitTemplate(String queueName, ConnectionFactory connectionFactory)
            throws RabbitmqCommunicateException
    {
        // AmqpTemplateは使いまわされるため、ディープコピーをする。
        RabbitTemplate template = null;
        try
        {
            template = (RabbitTemplate) BeanUtils.cloneBean(getContextBuilder().getAmqpTemplate(
                    queueName));
        }
        catch (Exception ex)
        {
            throw new RabbitmqCommunicateException(ex);
        }
        template.setConnectionFactory(connectionFactory);
        template.setExchange(queueName);
        template.setQueue(queueName);
        return template;
    }
824551
def create_environment(self, environment):
        

        uri = 'api/v3/environment/'

        data = dict()
        data['environments'] = list()
        data['environments'].append(environment)

        return super(ApiEnvironment, self).post(uri, data)
319920
def setup_app(command, conf, vars):
    """"""
    load_environment(conf.global_conf, conf.local_conf)
    setup_schema(command, conf, vars)
    bootstrap.bootstrap(command, conf, vars)
571345
def generate_mock_config(self, release):
        """"""
        mock_tmpl = pkg_resources.resource_string(__name__, 'templates/mock.mako')
        mock_dir = release['mock_dir'] = os.path.join(release['tmp_dir'], 'mock')
        mock_cfg = os.path.join(release['mock_dir'], release['mock'] + '.cfg')
        os.mkdir(mock_dir)
        for cfg in ('site-defaults.cfg', 'logging.ini'):
            os.symlink('/etc/mock/%s' % cfg, os.path.join(mock_dir, cfg))
        with file(mock_cfg, 'w') as cfg:
            mock_out = Template(mock_tmpl).render(**release)
            self.log.debug('Writing %s:\n%s', mock_cfg, mock_out)
            cfg.write(mock_out)
980957
def upload_celery_conf(command='celeryd', app_name=None, template_name=None, context=None):
    """"""

    app_name = app_name or command
    default = {'app_name': app_name, 'command': command}
    context = context or {}
    default.update(context)
    template_name = template_name or [u'supervisor/%s.conf' % command, u'supervisor/celery.conf']
    upload_supervisor_app_conf(app_name=app_name, template_name=template_name, context=default)
581260
def create_environ(self, req, payload):
        """"""
        ws_req = req.copy()

        del ws_req.controller_info

        ws_req.environ.pop("wsgi.input", None)
        ws_req.body_kwargs = payload.body

        ws_req.environ["REQUEST_METHOD"] = payload.method
        ws_req.method = payload.method

        ws_req.environ["PATH_INFO"] = payload.path
        ws_req.path = payload.path

        ws_req.environ["WS_PAYLOAD"] = payload
        ws_req.environ["WS_ORIGINAL"] = req

        ws_req.payload = payload
        ws_req.parent = req
        return {"WS_REQUEST": ws_req}