Beispiel #1
0
    def init(self, binary=False, behaviors=None):
        try:
            memcached_nodes = []
            
            if utils.is_ec2():
                stack = ec2_utils.get_stack()
                
                for node in stack.nodes:
                    if 'mem' in node.roles:
                        memcached_nodes.append(node.private_ip_address)
                
                if 0 == len(memcached_nodes):
                    raise Exception("[%s] unable to any find memcached servers" % self)
            else:
                # running locally so default to localhost
                memcached_nodes.append('127.0.0.1')
            
            self._client = pylibmc.Client(memcached_nodes, binary=binary, behaviors=behaviors)
            
            # Verify it works
            self._client.set('test', 'test', time=0)

        except Exception, e:
            logs.warning("[%s] unable to initialize memcached (%s)" % (self, e))
            self._client = None
            return False
Beispiel #2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__    = "Stamped ([email protected])"
__version__   = "1.0"
__copyright__ = "Copyright (c) 2011-2012 Stamped.com"
__license__   = "TODO"

import Globals
import os
import keys
import logs
from ec2_utils import get_stack

__stack_name = get_stack().instance.stack if get_stack() is not None else 'local'
__keys_dir = os.path.dirname(keys.__file__)

__api_keys = None
def _api_keys():
    """ Singleton for api-key definitions. On first load, opens keys/apikeys-<stack>.conf to load stack-specific
        api keys
    """

    global __api_keys, __stack_name, __keys_dir
    if __api_keys is not None:
        return __api_keys

    filename = 'apikeys-%s.conf' % __stack_name
    apikeys_path = '%s/%s' % (__keys_dir, filename)

    print ('apikeys_path: %s' % apikeys_path)
Beispiel #3
0
def is_bowser():
    import ec2_utils
    stack = ec2_utils.get_stack()
    return stack and str(stack['instance']['stack']) == 'bowser'