Insert a new nginx service definition
437554
def insert_nginx_service(definition):  # pragma: no cover
    """"""

    config_file = '/etc/nginx/sites-available/hfos.conf'
    splitter = "### SERVICE DEFINITIONS ###"

    with open(config_file, 'r') as f:
        old_config = "".join(f.readlines())

    pprint(old_config)

    if definition in old_config:
        print("Service definition already inserted")
        return

    parts = old_config.split(splitter)
    print(len(parts))
    if len(parts) != 3:
        print("Nginx configuration seems to be changed and cannot be "
              "extended automatically anymore!")
        pprint(parts)
        return

    try:
        with open(config_file, "w") as f:
            f.write(parts[0])
            f.write(splitter + "\n")
            f.write(parts[1])
            for line in definition:
                f.write(line)
            f.write("\n    " + splitter)
            f.write(parts[2])
    except Exception as e:
        print("Error during Nginx configuration extension:", type(e), e)
750081
def new(*args, &block)
      enclosing_resource ? service.build(*args, &block) : service.new(*args, &block)
    end
109983
def new(
    name,
    bucket,
    timeout,
    memory,
    description,
    subnet_ids,
    security_group_ids
):
    
    config = {}
    if timeout:
        config['timeout'] = timeout
    if memory:
        config['memory'] = memory
    if description:
        config['description'] = description
    if subnet_ids:
        config['subnet_ids'] = subnet_ids
    if security_group_ids:
        config['security_group_ids'] = security_group_ids

    lambder.create_project(name, bucket, config)
464363
def insert(opts={})
      mirror_api_method = opts[:mirror_api_method] || :subscriptions 
      subscription = mirror_api.subscriptions.insert.request_schema.new(
        collection:   opts[:collection] || DEFAULT_COLLECTION,
        userToken:    user_token,
        verifyToken:  verification_secret,
        callbackUrl:  opts[:callback_url] || client.callback_url,
        operation:    opts[:operations] || DEFAULT_OPERATIONS)
      result = google_client.execute(api_method: mirror_api.send(mirror_api_method).insert,
                                     body_object: subscription)
      result
    end
944198
def insert_after(after, new_middleware)
      @mutex.synchronize do
        return if @disabled_middleware.include?(new_middleware)
        return if @middlewares.include?(new_middleware)

        if after.is_a? Array
          index = @middlewares.rindex {|el| after.include?(el)}
        else
          index = @middlewares.rindex(after)
        end

        if index.nil?
          @middlewares << new_middleware
        else
          @middlewares.insert index + 1, new_middleware
        end
      end
    end
876570
def insert(self, space_no, *args):
        
        d = self.replyQueue.get()
        packet = RequestInsert(self.charset, self.errors, d._ipro_request_id, space_no, Request.TNT_FLAG_ADD, *args)
        self.transport.write(bytes(packet))
        return d.addCallback(self.handle_reply, self.charset, self.errors, None)
746579
def _create(self, **kwargs):
        '''
        '''

        try:
            return super(Service, self)._create(**kwargs)
        except HTTPError as ex:
            if "The configuration was updated successfully but could not be " \
                    "retrieved" not in ex.response.text:
                raise

            # BIG-IP® will create in Common partition if none is given.
            # In order to create the uri properly in this class's load,
            # drop in Common as the partition in kwargs.
            if 'partition' not in kwargs:
                kwargs['partition'] = 'Common'
            # Pop all but the necessary load kwargs from the kwargs given to
            # create. Otherwise, load may fail.
            kwargs_copy = kwargs.copy()
            for key in kwargs_copy:
                if key not in self._meta_data['required_load_parameters']:
                    kwargs.pop(key)
            # If response was created successfully, do a local_update.
            # If not, call to overridden _load method via load
            return self.load(**kwargs)
684562
def add(name, connection_uri, id_file="", o=[], config=None):
    
    storm_ = get_storm_instance(config)

    try:

        # validate name
        if '@' in name:
            raise ValueError('invalid value: "@" cannot be used in name.')

        user, host, port = parse(
            connection_uri,
            user=get_default("user", storm_.defaults),
            port=get_default("port", storm_.defaults)
        )

        storm_.add_entry(name, host, user, port, id_file, o)

        print(
            get_formatted_message(
                '{0} added to your ssh config. you can connect '
                'it by typing "ssh {0}".'.format(name),
            'success')
        )

    except ValueError as error:
        print(get_formatted_message(error, 'error'), file=sys.stderr)
        sys.exit(1)
763367
def add_service(self, cls):
        
        service_name = get_service_name(cls)
        container = self.container_cls(cls, self.config)
        self.service_map[service_name] = container
741798
def initialize(template, service_name, environment='dev'):
    
    template.SERVICE_NAME = os.getenv('SERVICE_NAME', service_name)
    template.SERVICE_ENVIRONMENT = os.getenv('ENV', environment).lower()
    template.DEFAULT_TAGS = troposphere.Tags(**{
        'service-name': template.SERVICE_NAME,
        'environment': template.SERVICE_ENVIRONMENT
    })
    template.add_version("2010-09-09")
    template.add_description("Stack for %s microservice" % service_name)
1313226
function createServer(serverName) {
        console.log("creating server", serverName)
        var server = servers[serverName] = net.createServer(handleConnection)
        ports.service(serverName, listen)

        function handleConnection(connection) {
            console.log("got incoming connection", connection)
            var stream = proxy.connect(serverName)
                , buffer = PauseStream().pause()
                , intermediate = through(stringer)

            connection.pipe(buffer)

            process.nextTick(pipe)

            function pipe() {
                buffer.pipe(intermediate)
                    .pipe(stream).pipe(connection)

                buffer.resume()
            }
        }

        function listen(port, ready) {
            server.listen(port, ready)
        }
    }
695927
def insert( index, *args)
      if !args.nil?
        pos = index
        args.each do |url| 
          convert = convert_remote_url( url )
          super( pos, convert )
          if index >= 0
            pos = pos + 1          
          end
        end
      else
        super( index, nil )  
      end
    end
266398
def _replace_service_arg(self, name, index, args):
        
        args[index] = self.get_instantiated_service(name)
459722
function insertProxy(proxies, namespace, serverType, proxy) {
    proxies[namespace] = proxies[namespace] || {};
    if (proxies[namespace][serverType]) {
        for (const attr in proxy) {
            if (proxy.hasOwnProperty(attr)) {
                proxies[namespace][serverType][attr] = proxy[attr];
            }
        }
    } else proxies[namespace][serverType] = proxy;
}
538401
def new_connection
      Connection.new(Backburner.configuration.beanstalk_url) { |conn| Backburner::Hooks.invoke_hook_events(self, :on_reconnect, conn) }
    end
648735
function create(options) {
  return knex(extend({
    client: "pg",
    debug: debug(),
    connection: connection(),
    pool: pool()
  }, options));
}
394334
def register(definition, options = {})
      url = options[:path] || ['/v1/agent/service/register']
      register = send_put_request(@conn, url, options, definition)
      register.status == 200
    end