Exemplo n.º 1
0
    def test_launch(self):
        instance_name = f"test-instance-{util.random_string()}"

        logging.info(f"Test launch: {instance_name}.")
        lxc.launch("images:alpine/3.10", instance_name)
        instance = util.find(
            lambda i: i["Name"] == instance_name and i["Status"] == "Running",
            lxc.list_(), None)
        self.assertIsNotNone(instance)
Exemplo n.º 2
0
    def test_delete(self):
        instance_name = f"test-instance-{util.random_string()}"
        lxc.launch("images:alpine/3.10", instance_name)
        lxc.stop([instance_name])
        lxc.delete([instance_name])

        instance = util.find(lambda i: i["Name"] == instance_name, lxc.list_(),
                             None)
        self.assertIsNone(instance)
Exemplo n.º 3
0
    def test_launch(self):
        util.mark("test_launch")

        instance_name = util.generate_instance_name()
        lxc.launch("images", "alpine/3.10", instance_name)
        instance = yurt_util.find(
            lambda i: i["Name"] == instance_name and i["Status"] == "Running",
            lxc.list_(),
            None
        )
        self.assertIsNotNone(instance)
Exemplo n.º 4
0
    def test_ping_from_host(self):
        instance_name = f"test-instance-{util.random_string()}"
        lxc.launch("images:alpine/3.10", instance_name)
        instance = util.find(
            lambda i: i["Name"] == instance_name and i["Status"] == "Running",
            lxc.list_(), None)
        self.assertIsNotNone(instance)

        logging.info(f"Test ping: {instance_name}")
        ip_address = instance["IP Address"]
        self.assertTrue(ping(ip_address))
Exemplo n.º 5
0
    def test_delete(self):
        util.mark("test_delete")

        instance_name = util.generate_instance_name()
        lxc.launch("images", "alpine/3.10", instance_name)
        lxc.stop([instance_name])
        lxc.delete([instance_name])

        instance = yurt_util.find(
            lambda i: i["Name"] == instance_name,
            lxc.list_(),
            None
        )
        self.assertIsNone(instance)
Exemplo n.º 6
0
    def get_ipv4_address(instance):
        ipv4_address = ""

        state = instance.state()
        if state.network:
            try:
                addresses = state.network["eth0"]["addresses"]
                ipv4_info = yurt_util.find(lambda a: a["family"] == "inet",
                                           addresses, {})
                ipv4_address = ipv4_info.get("address", "")
            except KeyError as e:
                logging.debug(f"Missing instance data: {e}")

        return ipv4_address
Exemplo n.º 7
0
    def test_ping_from_host(self):
        util.mark("test_ping_from_host")

        instance_name = util.generate_instance_name()
        lxc.launch("images", "alpine/3.10", instance_name)
        instance = yurt_util.find(
            lambda i: i["Name"] == instance_name and i["Status"] == "Running",
            lxc.list_(),
            None
        )
        self.assertIsNotNone(instance)

        logging.info(f"Test ping: {instance_name}")
        ip_address = instance["IP Address"]
        self.assertTrue(util.ping(ip_address))
Exemplo n.º 8
0
def get_cached_image_info(image: Dict):
    try:
        alias = image["update_source"]["alias"]
        server = image["update_source"]["server"]
        remote = find(lambda r: r["URL"] == server, REMOTES, None)

        if remote:
            source = f"{remote['Name']}:{alias}"
        else:
            raise LXCException("Unexpected source server: {}")

        return {
            "Alias": source,
            "Description": image["properties"]["description"]
        }

    except KeyError as e:
        logging.debug(e)
        logging.debug(f"Unexpected image schema: {image}")
Exemplo n.º 9
0
    def get_info(instance):
        try:
            addresses = instance["state"]["network"]["eth0"]["addresses"]
            ipv4_info = find(lambda a: a["family"] == "inet", addresses, {})
            ipv4_address = ipv4_info.get("address", "")
        except KeyError as e:
            logging.debug(f"Key Error: {e}")
            ipv4_address = ""
        except TypeError:
            ipv4_address = ""

        instance_config = instance["config"]
        architecture = instance_config.get("image.architecture", "")
        os_ = instance_config.get("image.os", "")
        release = instance_config.get("image.release", "")

        return {
            "Name": instance["name"],
            "Status": instance["state"]["status"],
            "IP Address": ipv4_address,
            "Image": f"{os_}/{release} ({architecture})"
        }