Esempio n. 1
0
 def real_start(self):
     pr, pw = gipc.pipe()
     self.puppet_process = gipc.start_process(target=SockServer(Puppet).run,
                                              kwargs={"pipe": pw})
     port = pr.get()
     self.puppet = SockClient(("localhost", port), keep_alive=False)
     self.puppet.hire_worker()
Esempio n. 2
0
class LXCService(ServiceBase):
    image = "brick-worker"
    # cmd_path = "brick-worker"
    port = 42424

    def __init__(self, s_id, conf):
        super(LXCService, self).__init__(s_id, conf)
        self.puppet_process = None
        self.name = "brick-%s" % self.s_id

    def get_ip(self, nic="eth0"):
        info = sh.lxc.info(self.name)
        if nic in info:
            for line in sh.lxc.info(self.name).splitlines():
                if nic in line:
                    groups = line.strip().split()
                    if len(groups) > 3 and "inet" == groups[1]:
                        return groups[2]
        gevent.sleep(0.5)
        return self.get_ip(nic)

    def real_start(self):
        sh.lxc.launch(self.image, self.name, p=self.conf)
        host = self.get_ip()
        self.puppet = SockClient((host, self.port), keep_alive=False)
        try_until(self.puppet.hire_worker)

    def real_terminate(self):
        self.puppet.fire_worker()
        self.puppet.shutdown()
        sh.lxc.stop(self.name)
        sh.lxc.delete(self.name)
Esempio n. 3
0
File: local.py Progetto: Tefx/Brick
class LXCService(ServiceBase):
    image = "brick-worker"
    # cmd_path = "brick-worker"
    port = 42424

    def __init__(self, s_id, conf):
        super(LXCService, self).__init__(s_id, conf)
        self.puppet_process = None
        self.name = "brick-%s" % self.s_id

    def get_ip(self, nic="eth0"):
        info = sh.lxc.info(self.name)
        if nic in info:
            for line in sh.lxc.info(self.name).splitlines():
                if nic in line:
                    groups = line.strip().split()
                    if len(groups) > 3 and "inet" == groups[1]:
                        return groups[2]
        gevent.sleep(0.5)
        return self.get_ip(nic)

    def real_start(self):
        sh.lxc.launch(self.image, self.name, p=self.conf)
        host = self.get_ip()
        self.puppet = SockClient((host, self.port), keep_alive=False)
        try_until(self.puppet.hire_worker)

    def real_terminate(self):
        self.puppet.fire_worker()
        self.puppet.shutdown()
        sh.lxc.stop(self.name)
        sh.lxc.delete(self.name)
Esempio n. 4
0
def test_worker():
    host = sys.argv[1]
    port = int(sys.argv[2])
    client = SockClient((host, port))
    client.hire_worker()
    gevent.sleep(1)
    client.fire_worker()
    client.shutdown()
    print "Successed!"
Esempio n. 5
0
File: worker.py Progetto: Tefx/Brick
def test_worker():
    host = sys.argv[1]
    port = int(sys.argv[2])
    client = SockClient((host, port))
    client.hire_worker()
    gevent.sleep(1)
    client.fire_worker()
    client.shutdown()
    print "Successed!"
Esempio n. 6
0
def brick_top():
    port = int(sys.argv[1])
    client = SockClient(("localhost", port))

    def output(window):
        curses.use_default_colors()
        while True:
            window.clear()
            window.addstr(build_info(client))
            window.refresh()
            time.sleep(1)

    curses.wrapper(output)
Esempio n. 7
0
File: qing.py Progetto: Tefx/Brick
class QingService(ServiceBase):
    port = 42424

    def __init__(self, s_id, conf,
                 api_keypath, zone, image, keypair, vxnets):
        super(QingService, self).__init__(s_id, conf)
        with open(api_keypath) as f:
            self.api_id = f.readline().split()[1].strip("'")
            self.api_key = f.readline().split()[1].strip("'")
        self.zone = zone
        self.image = image
        self.keypair = keypair
        self.instance_id = None
        self.vxnets = vxnets
        self.host = None

    def wait_booting(self, conn):
        ret = conn.describe_instances(instances=self.instance_id)
        if ret["instance_set"][0]["status"] != "running":
            gevent.sleep(3)
            return self.wait_booting(conn)
        elif not ret["instance_set"][0]["vxnets"][0]["private_ip"]:
            gevent.sleep(3)
            return self.wait_booting(conn)
        else:
            return ret["instance_set"][0]

    def conn_puppet(self):
        self.puppet = SockClient((self.host, self.port), keep_alive=False)
        self.puppet.hire_worker()

    def real_start(self):
        conn = connect_to_zone(self.zone, self.api_id, self.api_key)
        ret = conn.run_instances(image_id=self.image,
                                 instance_type=self.conf,
                                 login_mode="keypair",
                                 login_keypair=self.keypair,
                                 vxnets=[self.vxnets])
        self.instance_id = ret["instances"]
        ret = self.wait_booting(conn)
        self.host = ret["vxnets"][0]["private_ip"]
        self.conn_puppet()

    def real_terminate(self):
        self.puppet.fire_worker()
        self.puppet.shutdown()
        conn = connect_to_zone(self.zone, self.api_id, self.api_key)
        conn.terminate_instances(self.instance_id)
Esempio n. 8
0
File: local.py Progetto: Tefx/Brick
class ProcessService(ServiceBase):
    def __init__(self, s_id, conf):
        super(ProcessService, self).__init__(s_id, conf)
        self.puppet_process = None

    def real_start(self):
        pr, pw = gipc.pipe()
        self.puppet_process = gipc.start_process(target=SockServer(Puppet).run, kwargs={"pipe": pw})
        port = pr.get()
        self.puppet = SockClient(("localhost", port), keep_alive=False)
        self.puppet.hire_worker()

    def real_terminate(self):
        self.puppet.fire_worker()
        self.puppet.shutdown()
        self.puppet_process.terminate()
Esempio n. 9
0
class QingService(ServiceBase):
    port = 42424

    def __init__(self, s_id, conf, api_keypath, zone, image, keypair, vxnets):
        super(QingService, self).__init__(s_id, conf)
        with open(api_keypath) as f:
            self.api_id = f.readline().split()[1].strip("'")
            self.api_key = f.readline().split()[1].strip("'")
        self.zone = zone
        self.image = image
        self.keypair = keypair
        self.instance_id = None
        self.vxnets = vxnets
        self.host = None

    def wait_booting(self, conn):
        ret = conn.describe_instances(instances=self.instance_id)
        if ret["instance_set"][0]["status"] != "running":
            gevent.sleep(3)
            return self.wait_booting(conn)
        elif not ret["instance_set"][0]["vxnets"][0]["private_ip"]:
            gevent.sleep(3)
            return self.wait_booting(conn)
        else:
            return ret["instance_set"][0]

    def conn_puppet(self):
        self.puppet = SockClient((self.host, self.port), keep_alive=False)
        self.puppet.hire_worker()

    def real_start(self):
        conn = connect_to_zone(self.zone, self.api_id, self.api_key)
        ret = conn.run_instances(image_id=self.image,
                                 instance_type=self.conf,
                                 login_mode="keypair",
                                 login_keypair=self.keypair,
                                 vxnets=[self.vxnets])
        self.instance_id = ret["instances"]
        ret = self.wait_booting(conn)
        self.host = ret["vxnets"][0]["private_ip"]
        self.conn_puppet()

    def real_terminate(self):
        self.puppet.fire_worker()
        self.puppet.shutdown()
        conn = connect_to_zone(self.zone, self.api_id, self.api_key)
        conn.terminate_instances(self.instance_id)
Esempio n. 10
0
class ProcessService(ServiceBase):
    def __init__(self, s_id, conf):
        super(ProcessService, self).__init__(s_id, conf)
        self.puppet_process = None

    def real_start(self):
        pr, pw = gipc.pipe()
        self.puppet_process = gipc.start_process(target=SockServer(Puppet).run,
                                                 kwargs={"pipe": pw})
        port = pr.get()
        self.puppet = SockClient(("localhost", port), keep_alive=False)
        self.puppet.hire_worker()

    def real_terminate(self):
        self.puppet.fire_worker()
        self.puppet.shutdown()
        self.puppet_process.terminate()
Esempio n. 11
0
 def real_start(self):
     sh.lxc.launch(self.image, self.name, p=self.conf)
     host = self.get_ip()
     self.puppet = SockClient((host, self.port), keep_alive=False)
     try_until(self.puppet.hire_worker)
Esempio n. 12
0
 def conn_puppet(self):
     self.puppet = SockClient((self.host, self.port), keep_alive=False)
     self.puppet.hire_worker()
Esempio n. 13
0
File: local.py Progetto: Tefx/Brick
 def real_start(self):
     sh.lxc.launch(self.image, self.name, p=self.conf)
     host = self.get_ip()
     self.puppet = SockClient((host, self.port), keep_alive=False)
     try_until(self.puppet.hire_worker)
Esempio n. 14
0
File: local.py Progetto: Tefx/Brick
 def real_start(self):
     pr, pw = gipc.pipe()
     self.puppet_process = gipc.start_process(target=SockServer(Puppet).run, kwargs={"pipe": pw})
     port = pr.get()
     self.puppet = SockClient(("localhost", port), keep_alive=False)
     self.puppet.hire_worker()
Esempio n. 15
0
File: qing.py Progetto: Tefx/Brick
 def conn_puppet(self):
     self.puppet = SockClient((self.host, self.port), keep_alive=False)
     self.puppet.hire_worker()
Esempio n. 16
0
def list_status():
    port = int(sys.argv[1])
    client = SockClient(("localhost", port))
    print build_info(client)