Пример #1
0
def run_in_debug_mode(**options):
    from helper.worker import init_workers
    from conf import load_config
    from task import TaskStack

    global __debug_mode__
    load_config()
    init_workers()
    __debug_mode__ = True

    task = TaskStack(None)
    yield task
Пример #2
0
def validate_private_key(ssh_priv_key, with_config):
	config = load_config(os.path.join(BASE_DIR, "config.json") if with_config is None else with_config)

	if ssh_priv_key is None:
		ssh_priv_key = os.path.join(BASE_DIR, "%s.privkey" % config['IMAGE_NAME'])

	if not os.path.exists(ssh_priv_key):
		from fabric.operations import prompt
		ssh_priv_key_pwd = prompt("Give a password to your ssh key (or ENTER for no password)")

		if len(ssh_priv_key_pwd) == 0:
			ssh_priv_key_pwd = "\"\""

		with settings(warn_only=True):
			local("ssh-keygen -f %s -t rsa -b 4096 -N %s" % (ssh_priv_key, ssh_priv_key_pwd))

	ssh_pub_key = "%s.pub" % ssh_priv_key
	if not os.path.exists(ssh_priv_key) or not os.path.exists(ssh_pub_key):
		print "Sorry, there is no key made at %s" % ssh_priv_key
		return None

	return append_to_config({
		'SSH_PUB_KEY' : os.path.abspath(ssh_pub_key),
		'SSH_PRIV_KEY' : os.path.abspath(ssh_priv_key)
	}, with_config=with_config)
Пример #3
0
 def publish(self, topic, msg, conf, service):
     """
     Publish a message using the STOMP configuration from fedmsg.
     """
     fm_conf = fedmsg.config.load_config()
     for opt in ['stomp_uri', 'stomp_ssl_crt', 'stomp_ssl_key']:
         if opt not in fm_conf:
             raise RuntimeError('missing config: {0}'.format(opt))
     uris = self._to_host_and_port(fm_conf['stomp_uri'])
     conn = stomp.Connection(
         uris,
         version='1.1',
         use_ssl=True,
         ssl_cert_file=fm_conf['stomp_ssl_crt'],
         ssl_key_file=fm_conf['stomp_ssl_key'],
         ssl_ca_certs='/etc/pki/tls/certs/ca-bundle.crt',
         ssl_version=ssl.PROTOCOL_TLSv1_2,
         wait_on_receipt=True,
         timeout=10.0)
     conn.start()
     self.log.debug('Connecting to %s...', uris)
     conn.connect(wait=True)
     self.log.debug('Connected to %s', conn.get_host_and_port())
     dest = '.'.join([load_config().dest_prefix, topic])
     msg = json.dumps(msg)
     headers = {
         'destination': dest,
         'content-type': 'text/json',
         'content-length': len(msg),
         'receipt': str(uuid.uuid4())
     }
     self.log.debug('Sending message to %s, headers: %s', dest, headers)
     conn.send(message=msg, headers=headers)
     self.log.debug('Message successfully sent')
     conn.disconnect()
Пример #4
0
def set_svn_settings():
    m, svn, s = conf.load_config()
    client = pysvn.Client()
    client.set_default_username(svn['svn_username'])
    client.set_default_password(svn['svn_password'])
    url = svn['repository']
    return client, url
Пример #5
0
 def test_get_parsers(self):
     config = load_config(self.conf_file)
     parsers = get_parsers(config.items('parsers'))
     self.assertEquals(1, len(parsers))
     self.assertEquals("ncs_index_err",
                       parsers['ncs_index_err'].__class__.__module__)
     self.assertEquals("Parser",
                       parsers['ncs_index_err'].__class__.__name__)
Пример #6
0
    def configure():
        config = load_config()

        try:
            if len(config['source']) == 0:
                Watchman.get_source(config)

            update_config(config)
        except KeyboardInterrupt:
            log.error("Config cancelled by user")
Пример #7
0
    def configure():
        config = load_config()

        try:
            if len(config['source']) == 0:
                Watchman.get_source(config)

            update_config(config)
        except KeyboardInterrupt:
            log.error("Config cancelled by user")
Пример #8
0
 def __init__(self, name):
     super(Node, self).__init__()
     self.config = load_config()  # Load config from default path
     self.name = name
     self.client = mqtt.Client(client_id=name)
     self.client.user_data_set(self)
     self.client.on_connect = self.on_connect
     self.jobs = JobList(self.client)
     self.load_in_jobs()
     self.sensor_set = SensorSet()
     self.error_log = deque([], self.config['err_log_size'])
     self.logs = deque([], self.config['log_size'])
     self.channel = ChannelMgr(name)
     self.start_time = datetime.now()
     self.wake_time = datetime.now()
     # self.load_subscriptions()
     return
Пример #9
0
    def configure():
        config = load_config()

        try:
            while True:
                ans = raw_input("MENU \n 1. Add Source 2.Remove Source 3. View 4. Save \n")
                if (int(ans) == 1):
                    configurations.add_source(config)
                elif (int(ans) ==  2):
                    configurations.remove_source(config)
                elif (int(ans) == 3):
                    configurations.view_source(config)
                elif (int(ans) == 4):
                    update_config(config)
                else:
                    print "Huh? That wasn't even an option. -_-"
        except KeyboardInterrupt:
            log.error("Config cancelled by user")
Пример #10
0
def deploy(profile, stack_name, install_deps=False, extra_files=[]):
    """
    No automated tests as we don't want to deploy on each test run
    """
    config = conf.load_config('lambda.prd', ['upload_s3_bucket'])
    shell.shell('mkdir -p deploy')
    shell.shell('cp *.py *.yml requirements.txt deploy/')
    for f in extra_files:
        shell.shell('cp {} deploy/'.format(f))
    os.chdir('deploy')
    if install_deps:
        shell.shell('pip install -r requirements.txt -t .')
    shell.shell(
        'aws cloudformation package --template-file sam_pre.yml --output-template-file sam_post.yml --s3-bucket {} --profile {}'
        .format(config['upload_s3_bucket'], profile))
    shell.shell(
        'aws cloudformation deploy --template-file sam_post.yml --stack-name {} --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM --profile {}'
        .format(stack_name, profile))
    os.chdir('..')
Пример #11
0
    def configure():
        config = load_config()

        try:
            while True:
                ans = raw_input(
                    "MENU \n 1. Add Source 2.Remove Source 3. View 4. Save \n")
                if (int(ans) == 1):
                    configurations.add_source(config)
                elif (int(ans) == 2):
                    configurations.remove_source(config)
                elif (int(ans) == 3):
                    configurations.view_source(config)
                elif (int(ans) == 4):
                    update_config(config)
                else:
                    print "Huh? That wasn't even an option. -_-"
        except KeyboardInterrupt:
            log.error("Config cancelled by user")
Пример #12
0
def main(opts):
    config_mode = (opts.action in ACTIONS[:2]) and 'r' or 'w'
    config = conf.load_config(opts.config, config_mode)
    serviceURL = api.get_service_url(opts, config)
    username = conf.get_value(opts, config, 'username')
    password = conf.get_value(opts, config, 'password', secret=True)

    try:
        vim_client = api.connect(serviceURL, username, password)
   
        if opts.action == 'verify':
            verify.do_verify(config, opts, vim_client)
        elif opts.action == 'pillage':
            pillage.do_pillage(config, opts, vim_client)
        elif opts.action == 'repair':
            repair.do_repair(config, opts, vim_client)
        vim_client.Disconnect()
        rc = 0
    except SystemError, e:
        print(str(e.args))
        rc = 1
Пример #13
0
def load_options( argv, description, config_opts, default_config_file_path ):
   
   parser = conf.build_parser( argv[0], description, config_opts )
   opts = parser.parse_args( argv[1:] )
   
   # load everything into a dictionary and return it
   config = None 
   config_str = None
   config_file_path = None
   
   if hasattr( opts, "config" ) and opts.config != None:
      config_file_path = opts.config[0]
   else:
      config_file_path = default_config_file_path
   
   config_str = storage.read_file( config_file_path )
   if config_str == None:
      log.warning("Failed to read config file at %s" % config_file_path )
   
   config = conf.load_config( config_str, config_opts, opts )
   if config == None:
      raise Exception("Failed to parse configuration from %s" % config_file_path)
   
   return config
Пример #14
0
import sys
import logging
import conf
import psycopg2
import boto3
import json
import time

logging.basicConfig()
logger = logging.getLogger()
logger.setLevel(logging.INFO)


# load config
try:
    Config = conf.load_config('$LATEST')
except Exception as e:
    logger.error("ERROR: couldn't load conf file")
    sys.exit()

try:
    db_conn = psycopg2.connect(database=Config['DATABASE']['db'], user=Config['DATABASE']['user'],
                               password=Config['DATABASE']['password'],
                               host=Config['DATABASE']['host'], port=Config['DATABASE']['port'])
except Exception as e:
    logger.error("ERROR: Unexpected error: Could not connect to datbase instance.")
    sys.exit()

try:
    sns_client = boto3.client('sns')
except Exception as e:
Пример #15
0
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
from conf import load_config
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

engine = create_engine(load_config().DB_ENGINE)

DBSession = sessionmaker(bind=engine)




def transactional(fn):


    def transact(self,*args):
        session = DBSession()
        try:
            fn(self,session,*args)
            session.commit()
        except:
            session.rollback()
            raise


    transact.__name__ = fn.__name__
Пример #16
0
 def test_load(self):
     config = load_config(self.conf_file)
     self.assertEquals(9999, config.getint('common', 'port'))
     self.assertEquals([('ncs_index_err', 'ncs_index_err.Parser')],
                       config.items('parsers'))
Пример #17
0
def set_samba_settings():
    main, s, samba = conf.load_config()
    return main, samba
Пример #18
0
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer

import handler
import conf
import logging

users = []

#set logging
logging.basicConfig(level=logging.INFO)

#read configure file
config = conf.load_config('conf/pyscribe.conf')

handler = handler.LogHandler()
#set parsers
handler.parsers = conf.get_parsers(config.items('parsers'))

processor = scribe.Processor(handler)
transport = TSocket.TServerSocket(config.getint('common', 'port'))
tfactory = TTransport.TFramedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()

server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)

print 'Starting the server...'
server.serve()
print 'done.'
Пример #19
0
import redis
import rom
from datetime import datetime
from conf import load_config
from uuid import uuid4
from json import dumps
config = load_config()
rom.util.set_connection_settings(host=config['REDIS_URL'], port=config['REDIS_PORT'])


class Location(rom.Model):
    name = rom.String(required=True, index=True, keygen=rom.FULL_TEXT)
    url = rom.String(required=True, index=True, unique=True, keygen=rom.FULL_TEXT)
    description = rom.String(required=True)
    parent = rom.ManyToOne('Location', on_delete='cascade')
    children = rom.OneToMany('Location', column='parent')
    nodes = rom.OneToMany('Node', column='location')
    # outline of grid coordinates for map
    def to_json(self):
        d = {}
        d['name'] = str(self.name.decode('utf-8'))
        d['description'] = str(self.description.decode('utf-8'))
        d['url'] = str(self.url.decode('utf-8'))
        d['parent'] = {'name': self.parent.name.decode('utf-8'), 'url': self.parent.url.decode('utf-8')}
        d['children'] = [{'name':c.name.decode('utf-8'), 'url':c.url.decode('utf-8')} for c in self.children]
        d['nodes'] = [str(n.uid.decode('utf-8')) for n in self.nodes]
        return dumps(d)

class Sensor(rom.Model):
    name = rom.String(required=True, index=True, keygen=rom.FULL_TEXT)
    uid = rom.String(required=True, index=True, unique=True, keygen=rom.FULL_TEXT)
Пример #20
0
 def test_get_parsers(self):
     config = load_config(self.conf_file)
     parsers = get_parsers(config.items('parsers'))
     self.assertEquals(1, len(parsers))
     self.assertEquals("ncs_index_err", parsers['ncs_index_err'].__class__.__module__)
     self.assertEquals("Parser", parsers['ncs_index_err'].__class__.__name__)
Пример #21
0
 def test_load(self):
     config = load_config(self.conf_file)
     self.assertEquals(9999, config.getint('common', 'port'))
     self.assertEquals([('ncs_index_err','ncs_index_err.Parser')], config.items('parsers'))
Пример #22
0
from celery import Celery
from conf import load_config
from celery import platforms


reload(sys)
sys.path.append(os.path.join(os.path.dirname(__file__), "./"))

default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
    reload(sys)
    sys.setdefaultencoding(default_encoding)

celery = Celery('PinPin',)

conf = load_config()

from beatjob import CELERYBEAT_SCHEDULE

celery.conf.update(
    BROKER_URL=conf.BROKER_URL,
    CELERY_RESULT_BACKEND=conf.CELERY_RESULT_BACKEND,
    CELERY_TASK_SERIALIZER=conf.CELERY_TASK_SERIALIZER,
    CELERY_RESULT_SERIALIZER=conf.CELERY_RESULT_SERIALIZER,
    CELERY_ACCEPT_CONTENT=conf.CELERY_ACCEPT_CONTENT,
    CELERY_TIMEZONE=conf.CELERY_TIMEZONE,
    CELERYBEAT_SCHEDULE=CELERYBEAT_SCHEDULE
)


platforms.C_FORCE_ROOT = True
Пример #23
0
 def __init__(self):
     super(CustomParser, self).__init__()
     self.conf = load_config()
     self.log = logging.getLogger(__name__)