Beispiel #1
0
from traceback import format_exc
from struct import unpack
from errno import EINTR
from time import time
import socket
import signal

from clusto.services.config import conf, get_logger
log = get_logger('clusto.dhcp', 'INFO')

import logging
runtime = logging.getLogger('scapy.runtime')
runtime.setLevel(logging.ERROR)
loading = logging.getLogger('scapy.loading')
loading.setLevel(logging.ERROR)

from scapy.all import BOOTP, DHCP, DHCPTypes, DHCPOptions, DHCPRevOptions
from IPy import IP

import clusto

extra = conf('dhcp.extra_options')
extra = dict([(int(k), str(v)) for k, v in extra.items()])
DHCPOptions.update(extra)

for k,v in DHCPOptions.iteritems():
    if type(v) is str:
        n = v
        v = None
    else:
        n = v.name
Beispiel #2
0
Datei: snmp.py Projekt: wt/clusto
#!/usr/bin/env python
from socket import socket, AF_INET, SOCK_DGRAM
from traceback import format_exc
from time import strftime, time, localtime, sleep
from struct import unpack
import sys

import logging

from clusto.services.config import conf, get_logger
log = get_logger('clusto.snmp', 'INFO')

import logging
runtime = logging.getLogger('scapy.runtime')
runtime.setLevel(logging.ERROR)
loading = logging.getLogger('scapy.loading')
loading.setLevel(logging.ERROR)

from scapy.all import SNMP

from clusto.drivers import IPManager, PenguinServer
import clusto

sys.path.insert(0, '/var/lib/clusto')
import rackfactory

def update_clusto(trap):
    ts = strftime('[%Y-%m-%d %H:%M:%S]')
    if trap['operation'] != 1:
        return
Beispiel #3
0
from collections import defaultdict
from traceback import format_exc
from struct import unpack
from errno import EINTR
import socket

from clusto.services.config import conf, get_logger

log = get_logger('clusto.dhcp', 'INFO')

import logging

runtime = logging.getLogger('scapy.runtime')
runtime.setLevel(logging.ERROR)
loading = logging.getLogger('scapy.loading')
loading.setLevel(logging.ERROR)

from scapy.all import BOOTP, DHCP, DHCPTypes, DHCPOptions, DHCPRevOptions
from IPy import IP

import clusto

extra = conf('dhcp.extra_options')
extra = dict([(int(k), str(v)) for k, v in extra.items()])
DHCPOptions.update(extra)

for k, v in DHCPOptions.iteritems():
    if type(v) is str:
        n = v
        v = None
    else:
Beispiel #4
0
from traceback import format_exc
from struct import unpack
from errno import EINTR
from time import time
import socket
import signal

from clusto.services.config import conf, get_logger

log = get_logger("clusto.dhcp", "INFO")

import logging

runtime = logging.getLogger("scapy.runtime")
runtime.setLevel(logging.ERROR)
loading = logging.getLogger("scapy.loading")
loading.setLevel(logging.ERROR)

from scapy.all import BOOTP, DHCP, DHCPTypes, DHCPOptions, DHCPRevOptions
from IPy import IP

from clustohttp import ClustoProxy

clusto = ClustoProxy(conf("dhcp.api_url"))

extra = conf("dhcp.extra_options")
extra = dict([(int(k), str(v)) for k, v in extra.items()])
DHCPOptions.update(extra)

for k, v in DHCPOptions.iteritems():
    if type(v) is str:
Beispiel #5
0
try:
    import simplejson as json
except ImportError:
    import json

from webob import Request, Response
from traceback import format_exc
from urllib import unquote_plus
import new
import re

from clusto.drivers import Driver, IPManager
import clusto

from clusto.services.config import conf, get_logger
log = get_logger('clusto.http', 'INFO')


def unclusto(obj):
    '''
    Convert an object to a representation that can be safely serialized into
    JSON.
    '''
    if type(obj) in (str, unicode, int) or obj == None:
        return obj
    if isinstance(obj, clusto.Attribute):
        return {
            'key': obj.key,
            'value': unclusto(obj.value),
            'subkey': obj.subkey,
            'number': obj.number,
Beispiel #6
0
    import simplejson as json
except ImportError:
    import json

from webob import Request, Response
from traceback import format_exc
from urllib import unquote_plus
import re
import os

from clusto.drivers import Driver, IPManager
import clusto.script_helper
import clusto

from clusto.services.config import conf, get_logger
log = get_logger('clusto.http', 'INFO')

conf = clusto.script_helper.load_config(os.environ.get('CLUSTOCONFIG', '/etc/clusto/clusto.conf'))
clusto.connect(conf)


def unclusto(obj, prefetch_attrs=None):
    '''
    Convert an object to a representation that can be safely serialized into
    JSON.
    '''
    if type(obj) in (str, unicode, int) or obj is None:
        return obj
    if type(obj) in (list, dict):
        return json.dumps(obj)
    if isinstance(obj, clusto.Attribute):
QUEUE_HOSTS = conf('barker.hosts')
QUEUE_EXCHANGE = conf('barker.exchange')
QUEUE_NAME = conf('barker.queue')
QUEUE_VHOST = conf('barker.vhost')
QUEUE_USER = conf('barker.user')
QUEUE_PASSWORD = conf('barker.password')

EC2_SUBKEYS = {
    'ami-id': 'ami',
    'kernel-id': 'kernel',
    'instance-type': 'type',
    'local-hostname': 'private-dns',
    'public-hostname': 'public-dns',
}

log = get_logger('clusto.barker', level='DEBUG')

def barker_callback(body):
    if not 'ec2' in body:
        return
    if not 'instance-id' in body['ec2']:
        return
    ec2 = body['ec2']
    log.debug(ec2['instance-id'])

    try:
        clusto.begin_transaction()
        server = clusto.get_or_create(ec2['instance-id'], SGServer)

        if not server.attr_values(key='ec2', subkey='instance-id'):
            server.set_attr(key='ec2', subkey='instance-id', value=ec2['instance-id'])
Beispiel #8
0
try:
    import simplejson as json
except ImportError:
    import json

from webob import Request, Response
from traceback import format_exc
from urllib import unquote_plus
import re

from clusto.drivers import Driver, IPManager
import clusto

from clusto.services.config import conf, get_logger

log = get_logger("clusto.http", "INFO")


def unclusto(obj):
    """
    Convert an object to a representation that can be safely serialized into
    JSON.
    """
    if type(obj) in (str, unicode, int) or obj == None:
        return obj
    if isinstance(obj, clusto.Attribute):
        return {
            "key": obj.key,
            "value": unclusto(obj.value),
            "subkey": obj.subkey,
            "number": obj.number,
Beispiel #9
0
#!/usr/bin/env python
from socket import socket, AF_INET, SOCK_DGRAM
from traceback import format_exc
from time import strftime, time, localtime, sleep
from struct import unpack
import sys

import logging

from clusto.services.config import conf, get_logger

log = get_logger("clusto.snmp", "INFO")

import logging

runtime = logging.getLogger("scapy.runtime")
runtime.setLevel(logging.ERROR)
loading = logging.getLogger("scapy.loading")
loading.setLevel(logging.ERROR)

from scapy.all import SNMP

from clusto.drivers import IPManager, PenguinServer
import clusto

sys.path.insert(0, "/var/lib/clusto")
import rackfactory


def update_clusto(trap):
    ts = strftime("[%Y-%m-%d %H:%M:%S]")