Пример #1
0
def setup():
    spawner.spawn(host=config.BEANSTALKD_HOST,
                  port=config.BEANSTALKD_PORT,
                  path=config.BEANSTALKD)
    global conn
    conn = serverconn.ServerConn(config.BEANSTALKD_HOST,
                                 int(config.BEANSTALKD_PORT))
Пример #2
0
def test_ServerConn_fails_to_connect_with_a_reasonable_exception():
    # it may be nicer not to throw a socket error here?
    try:
        serverconn.ServerConn(config.BEANSTALKD_HOST,
                              int(config.BEANSTALKD_PORT) + 1)
    except socket.error, reason:
        pass
Пример #3
0
def main():
    try:
        print 'handling args'
        clienttype = sys.argv[1]
        server = sys.argv[2]
        try:
            port = int(sys.argv[3])
        except:
            port = 11300

        print 'setting up connection'
        connection = serverconn.ServerConn(server, port)
        connection.job = job.Job
        if clienttype == 'producer':
            print 'starting producer loop'
            producer_main(connection)
        elif clienttype == 'consumer':
            print 'starting consumer loop'
            consumer_main(connection)
        else:
            raise Exception('foo')
    except Exception, e:
        print "usage: example.py TYPE server [port]"
        print " TYPE is one of: [producer|consumer]"
        raise
        sys.exit(1)
Пример #4
0
def setup():
    global server_pid, conn, config
    server_pid = os.spawnl(os.P_NOWAIT,
                           os.path.join(config.BPATH, config.BEANSTALKD),
                           os.path.join(config.BPATH, config.BEANSTALKD), '-l',
                           config.BEANSTALKD_HOST, '-p',
                           config.BEANSTALKD_PORT)
    print "server started at process", server_pid
    time.sleep(0.1)
    conn = serverconn.ServerConn(config.BEANSTALKD_HOST,
                                 int(config.BEANSTALKD_PORT))
Пример #5
0
def main():
    try:
        SevAddr = sys.argv[1]
        try:
            SevPort = int(sys.argv[2])
        except:
            SevPort = 11300

        ImgLocation = sys.argv[3]

        MsgTube = sys.argv[4]

        connection = serverconn.ServerConn(SevAddr, SevPort)
        connection.job = job.Job
        PutImgTestRequest(connection, ImgLocation, MsgTube)
    except Exception, e:
        print "Usage: MsgQueueProxy.py Server Port ImgLocation MsgTube"
        raise
        sys.exit(1)
Пример #6
0
def connect(host='localhost', port=11300):
    return serverconn.ServerConn(host, port)
Пример #7
0
def queue_generator_job(node, email_user, config_only=False):
    """
  Queues a generator job via the beanstalk daemon.
  """
    assert (isinstance(node, Node))

    if not getattr(settings, 'IMAGE_GENERATOR_ENABLED', None):
        return

    # Open up a connection with beanstalkd
    queue = serverconn.ServerConn("127.0.0.1", 11300)
    queue.use("generator")

    # Prepare job metadata from profile information
    subnets = []
    for subnet in node.subnet_set.filter(
            allocated=True).order_by('-gen_iface_type'):
        # Resolve actual interface name
        try:
            iface = IfaceTemplate.objects.get(template=node.profile.template,
                                              type=subnet.gen_iface_type)
        except IfaceTemplate.DoesNotExist:
            continue

        subnets.append({
            'network': subnet.subnet,
            'cidr': subnet.cidr,
            'iface': iface.ifname,
            'dhcp': subnet.gen_dhcp
        })

    vpn_limit_down = None
    try:
        vpn_limit_down = node.gw_policy.get(
            addr=node.vpn_mac_conf,
            family=PolicyFamily.Ethernet).tc_class.bandwidth
    except:
        pass

    data = {
        'uuid':
        node.uuid,
        'ip':
        node.ip,
        'hostname':
        node.name,
        'vpn_username':
        node.owner.username,
        'vpn_password':
        '******',
        'vpn_mac':
        node.vpn_mac_conf,
        'project':
        node.project.name,
        'ssid':
        node.configured_essid,
        'channel':
        node.profile.channel,
        'rx_ant':
        node.profile.antenna,
        'tx_ant':
        node.profile.antenna,
        'root_pass':
        node.profile.root_pass,
        'vpn':
        node.profile.use_vpn,
        'vpn_limit_down':
        vpn_limit_down,
        'vpn_limit_up':
        node.profile.vpn_egress_limit,
        'captive_portal':
        node.project.captive_portal,
        'wan_dhcp':
        node.profile.wan_dhcp,
        'wan_ip':
        node.profile.wan_ip,
        'wan_cidr':
        node.profile.wan_cidr,
        'wan_gw':
        node.profile.wan_gw,
        'lan_wifi_bridge':
        node.profile.lan_bridge,
        'openwrt_ver':
        node.profile.template.openwrt_version,
        'router_name':
        node.profile.template.short_name,
        'arch':
        node.profile.template.arch,
        'iface_wifi':
        node.profile.template.iface_wifi,
        'iface_lan':
        node.profile.template.iface_lan,
        'iface_wan':
        node.profile.template.iface_wan,
        'driver':
        node.profile.template.driver,
        'port_layout':
        node.profile.template.port_layout,
        'imagebuilder':
        node.profile.template.imagebuilder,
        'imagefiles':
        [(x.name, x.type) for x in node.profile.template.imagefiles.all()],
        'opt_pkg': [x.name for x in node.profile.optional_packages.all()],
        'subnets':
        subnets,
        'lan_wan_switch':
        not node.profile.template.iface_lan
        and node.has_allocated_subnets(IfaceType.LAN),
        'only_config':
        config_only,
        'email':
        email_user.email
    }

    # Add per-project packages
    for x in node.project.packages.all():
        data['opt_pkg'].append(x.name)

    # Queue the actual job
    j = job.Job(conn=queue)
    j.data = data
    j.Queue()