示例#1
0
文件: dhcp.py 项目: way-2-go/clusto
    def handle_discover(self, request):
        if conf("dhcp.update_ipmi"):
            self.update_ipmi(request)

        attrs = [{"key": "port-nic-eth", "subkey": "mac", "number": 1, "value": request.hwaddr}]
        server = clusto.get_entities(attrs=attrs)

        if not server:
            return

        if len(server) > 1:
            log.warning(
                "More than one server with address %s: %s" % (request.hwaddr, ", ".join([x.name for x in server]))
            )
            return

        server = server[0]

        enabled = server.attrs(key="dhcp", subkey="enabled", merge_container_attrs=True)
        if not enabled or not enabled[0].value:
            log.info("DHCP not enabled for %s" % server.name)
            return

        ips = defaultdict(dict)
        for attr in server.attrs(key="ip"):
            ips[attr.number][attr.subkey] = attr.value

        for num, ip in ips.items():
            if IP(ip["ipstring"]).iptype() != "PRIVATE":
                del ips[num]
        if not ips:
            log.info("No private IP assigned for %s" % server.name)
            return

        ip = ips.values().pop()
        ipman = dict([(x.key, x.value) for x in ip["manager"].attrs(subkey="property")])
        # ipman = dict([(x['key'], x['value']) for x in clusto.get_ip_manager(ip).attrs() if x['subkey'] == 'property'])
        ipy = IP("%s/%s" % (ip["ipstring"], ipman["netmask"]), make_net=True)

        options = {
            "server_id": self.server_id,
            "lease_time": 3600,
            "renewal_time": 1600,
            "subnet_mask": ipman["netmask"],
            "broadcast_address": ipy.broadcast().strNormal(),
            "router": ipman["gateway"],
            "hostname": server.hostname,
        }

        log.info("Sending offer to %s, options: %s" % (server.name, options))

        for attr in server.attrs(key="dhcp", merge_container_attrs=True):
            options[attr.subkey] = attr.value

        response = DHCPResponse(type="offer", offerip=ip["ipstring"], options=options, request=request)
        self.offers[request.packet.chaddr] = response
        self.send("255.255.255.255", response.build())
示例#2
0
文件: dhcp.py 项目: david415/clusto
    def handle_discover(self, request):
        if conf("dhcp.update_ipmi"):
            self.update_ipmi(request)

        attrs = [{"key": "port-nic-eth", "subkey": "mac", "number": 1, "value": request.hwaddr}]
        server = clusto.get_entities(attrs=attrs)

        if not server:
            return

        if len(server) > 1:
            log.warning(
                "More than one server with address %s: %s" % (request.hwaddr, ", ".join([x.name for x in server]))
            )
            return

        server = server[0]

        enabled = server.attrs(key="dhcp", subkey="enabled", merge_container_attrs=True)
        if not enabled or not enabled[0]["value"]:
            log.info("DHCP not enabled for %s" % server.name)
            return

        ip = server.attrs(key="ip", subkey="ipstring")
        if not ip:
            log.info("No IP assigned for %s" % server.name)
            return
        else:
            ip = ip[0]["value"]

        ipman = dict([(x["key"], x["value"]) for x in clusto.get_ip_manager(ip).attrs() if x["subkey"] == "property"])
        ipy = IP("%s/%s" % (ip, ipman["netmask"]), make_net=True)

        options = {
            "server_id": self.server_id,
            "lease_time": 3600,
            "renewal_time": 1600,
            "subnet_mask": ipman["netmask"],
            "broadcast_address": ipy.broadcast().strNormal(),
            "router": ipman["gateway"],
            "hostname": server.name,
        }

        log.info("Sending offer to %s" % server.name)

        for attr in server.attrs(key="dhcp", merge_container_attrs=True):
            options[attr["subkey"]] = attr["value"]

        response = DHCPResponse(type="offer", offerip=ip, options=options, request=request)
        self.offers[request.packet.chaddr] = response
        self.send("255.255.255.255", response.build())
示例#3
0
    def handle_discover(self, request):
        if conf('dhcp.update_ipmi'):
            self.update_ipmi(request)

        attrs = [{
            'key': 'port-nic-eth',
            'subkey': 'mac',
            'number': 1,
            'value': request.hwaddr,
        }]
        server = clusto.get_entities(attrs=attrs)

        if not server:
            return

        if len(server) > 1:
            log.warning('More than one server with address %s: %s' % (request.hwaddr, ', '.join([x.name for x in server])))
            return
        
        server = server[0]

        enabled = server.attrs(key='dhcp', subkey='enabled', merge_container_attrs=True)
        if not enabled or not enabled[0].value:
            log.info('DHCP not enabled for %s' % server.name)
            return

        ip = server.attrs(key='ip', subkey='ipstring')
        if not ip:
            log.info('No IP assigned for %s' % server.name)
            return
        else:
            ip = ip[0].value

        ipman = server.attrs(key='ip', subkey='manager')
        if not ipman:
            log.info('Could not find the ip manager for %s' % server.name)
            return
        else:
            ipman = ipman[0].value
        ipman = dict([(x.key, x.value) for x in ipman.attrs(subkey='property')])
        #ipman = dict([(x['key'], x['value']) for x in clusto.get_ip_manager(ip).attrs() if x['subkey'] == 'property'])
        ipy = IP('%s/%s' % (ip, ipman['netmask']), make_net=True)

        options = {
            'server_id': self.server_id,
            'lease_time': 3600,
            'renewal_time': 1600,
            'subnet_mask': ipman['netmask'],
            'broadcast_address': ipy.broadcast().strNormal(),
            'router': ipman['gateway'],
            'hostname': server.hostname,
        }

        log.info('Sending offer to %s, options: %s' % (server.name, options))

        for attr in server.attrs(key='dhcp', merge_container_attrs=True):
            options[attr.subkey] = attr.value

        response = DHCPResponse(type='offer', offerip=ip, options=options, request=request)
        self.offers[request.packet.chaddr] = response
        self.send('255.255.255.255', response.build())
示例#4
0
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
    DHCPRevOptions[n] = (k,v)

class DHCPRequest(object):
    def __init__(self, packet):
        self.packet = packet
        self.parse()
示例#5
0
文件: dhcp.py 项目: david415/clusto
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:
        n = v
        v = None
    else:
        n = v.name
    DHCPRevOptions[n] = (k, v)


class DHCPRequest(object):
示例#6
0
文件: dhcp.py 项目: verma7/clusto
    def handle_discover(self, request):
        if conf('dhcp.update_ipmi'):
            self.update_ipmi(request)

        attrs = [{
            'key': 'port-nic-eth',
            'subkey': 'mac',
            'number': 1,
            'value': request.hwaddr,
        }]
        server = clusto.get_entities(attrs=attrs)

        if not server:
            return

        if len(server) > 1:
            log.warning('More than one server with address %s: %s' %
                        (request.hwaddr, ', '.join([x.name for x in server])))
            return

        server = server[0]

        enabled = server.attrs(key='dhcp',
                               subkey='enabled',
                               merge_container_attrs=True)
        if not enabled or not enabled[0].value:
            log.info('DHCP not enabled for %s' % server.name)
            return

        ips = defaultdict(dict)
        for attr in server.attrs(key='ip'):
            ips[attr.number][attr.subkey] = attr.value

        for num, ip in ips.items():
            if IP(ip['ipstring']).iptype() != 'PRIVATE':
                del ips[num]
        if not ips:
            log.info('No private IP assigned for %s' % server.name)
            return

        ip = ips.values().pop()
        ipman = dict([(x.key, x.value)
                      for x in ip['manager'].attrs(subkey='property')])
        #ipman = dict([(x['key'], x['value']) for x in clusto.get_ip_manager(ip).attrs() if x['subkey'] == 'property'])
        ipy = IP('%s/%s' % (ip['ipstring'], ipman['netmask']), make_net=True)

        options = {
            'server_id': self.server_id,
            'lease_time': 3600,
            'renewal_time': 1600,
            'subnet_mask': ipman['netmask'],
            'broadcast_address': ipy.broadcast().strNormal(),
            'router': ipman['gateway'],
            'hostname': server.hostname,
        }

        log.info('Sending offer to %s, options: %s' % (server.name, options))

        for attr in server.attrs(key='dhcp', merge_container_attrs=True):
            options[attr.subkey] = attr.value

        response = DHCPResponse(type='offer',
                                offerip=ip['ipstring'],
                                options=options,
                                request=request)
        self.offers[request.packet.chaddr] = response
        self.send('255.255.255.255', response.build())
示例#7
0
文件: dhcp.py 项目: verma7/clusto
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
    DHCPRevOptions[n] = (k, v)


class DHCPRequest(object):
    def __init__(self, packet):
        self.packet = packet
from clusto import script_helper
from sgext.drivers import SGServer, EC2Zone
from clusto.drivers import Pool
from clusto.services.config import conf, get_logger
import clusto
import sgext

import kombu

from traceback import format_exc
from time import sleep, time
import logging
import sys

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')
示例#9
0
文件: dhcp.py 项目: way-2-go/clusto
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
    DHCPRevOptions[n] = (k, v)


class DHCPRequest(object):
    def __init__(self, packet):
        self.packet = packet