Ejemplo n.º 1
0
class TestName:

    def print_images(self):
        images = self.p.images()
        print(Printer.flatwrite(images,
                                sort_keys=("name"),
                                order=["name", "provider", "version"],
                                header=["Name", "Provider", "Version"]))

    def next_name(self):
        self.name_generator.incr()
        self.new_name = str(self.name_generator)
        return self.new_name

    def setup(self):
        banner("setup", c="-")
        self.user = Config()["cloudmesh.profile.user"]
        self.name_generator = Name(
            experiment="exp",
            group="grp",
            user=self.user,
            kind="vm",
            counter=1)

        self.name = str(self.name_generator)
        self.name_generator.incr()
        self.new_name = str(self.name_generator)
        self.p = Provider(name="vbox")

    def test_01_list_images(self):
        HEADING()
        self.print_images()

#    def test_03_delete_image(self):
#        HEADING()
#        name = "hashicorp/precise64"
#        try:
#            images = self.p.delete_image(name)
#            print ("delete", name)
#        except:
#            print ("image", name, "nor found")
#        self.print_images()

#    def test_03_add_image(self):
#        HEADING()
#        name = "hashicorp/precise64"
#
#        images = self.p.add_image(name)
#        self.print_images()

    def test_04_list_vm(self):
        HEADING()

        name = self.next_name()

        print ("Name", name)

        vms = self.p.list()
        pprint (vms)
        '''
Ejemplo n.º 2
0
class Provider(object):
    def __init__(self,
                 name=None,
                 configuration="~/.cloudmesh/.cloudmesh4.yaml"):
        self.kind = Config(
            configuration)["cloudmesh"]["cloud"][name]["cm"]["kind"]
        self.name = name

        # Console.msg("FOUND Kind", self.kind)

        if self.kind in ["openstack", "aws"]:
            self.p = LibCloudProvider(name=name, configuration=configuration)
        elif self.kind in ["vagrant", "virtualbox"]:
            self.p = VirtualboxCloudProvider(name=name,
                                             configuration=configuration)

    def cloudname(self):
        return self.name

    @DatabaseUpdate()
    def keys(self):
        return self.p.keys()

    @DatabaseUpdate()
    def list(self):
        return self.p.list()

    @DatabaseUpdate()
    def images(self):
        return self.p.images()

    @DatabaseUpdate()
    def flavor(self):
        return self.p.flavors()

    def add_collection(self, d, *args):
        if d is None:
            return None
        label = '-'.join(args)
        for entry in d:
            entry['collection'] = label
        return d

    @DatabaseUpdate()
    def images(self):
        return self.p.images()

    # name
    # cloud
    # kind
    @DatabaseUpdate()
    def flavors(self):
        return self.p.flavors()

    def start(self, name=None):
        return self.p.start(name=name)

    def stop(self, name=None):
        return self.p.stop(name=name)

    def info(self, name=None):
        return self.p.info(name=name)

    def resume(self, name=None):
        return self.p.resume(name=name)

    def reboot(self, name=None):
        return self.p.reboot(name=name)

    def create(self, name=None, image=None, size=None, timeout=360, **kwargs):
        self.p.create(name=name, image=image, size=size, timeout=360, **kwargs)

    def rename(self, name=None, destination=None):
        self.p.rename(name=name, destination=name)
class TestName:
    image_test = False
    vbox = '6.0.4'
    image_name = "generic/ubuntu1810"
    size = 1024
    cloud = "vagrant"

    def print_images(self):
        images = self.p.images()
        print(
            Printer.flatwrite(images,
                              sort_keys=["name"],
                              order=["name", "provider", "version"],
                              header=["Name", "Provider", "Version"]))

    def next_name(self):
        self.name_generator.incr()
        self.new_name = str(self.name_generator)
        return self.new_name

    def setup(self):
        banner("setup", c="-")
        self.user = Config()["cloudmesh.profile.user"]
        self.name_generator = Name(experiment="exp",
                                   group="grp",
                                   user=self.user,
                                   kind="vm",
                                   counter=1)

        self.name = str(self.name_generator)
        self.name_generator.incr()
        self.new_name = str(self.name_generator)
        self.p = Provider(name=self.cloud)

    def test_01_version(self):
        HEADING()
        r = self.p.version()
        pprint(r)
        assert self.vbox_version == r["virtualbox"]["extension"]["version"]
        assert self.vbox_version == r["virtualbox"]["version"]

    def test_02_list_os(self):
        HEADING()
        ostypes = self.p.list_os()
        print(
            Printer.write(ostypes,
                          order=[
                              "id", "64_bit", "description", "family_descr",
                              "family_id"
                          ],
                          header=[
                              "id", "64_bit", "description", "family_descr",
                              "family_id"
                          ]))

    def test_03_name(self):
        HEADING()
        print(self.name)
        assert self.name == "exp-grp-{user}-vm-1".format(user=self.user)

    def test_04_list_images(self):
        HEADING()
        self.print_images()

    def test_05_delete_image(self):
        HEADING()
        if self.image_test:
            name = "generic/ubuntu1810"
            try:
                images = self.p.delete_image(self.image_name)
                print("delete", self.image_name)
            except:
                print("image", self.image_name, "nor found")
            self.print_images()
        else:
            print("not executed as image_test is not True. ok")

    def test_06_add_image(self):
        HEADING()
        if self.image_test:
            images = self.p.add_image(self.image_name)
            print("I", images)
            self.print_images()
            assert images.status == 0
        else:
            print("not executed as image_test is not True. ok")

    def test_07_list_vm(self):
        HEADING()

        vms = self.p.info()
        pprint(vms)
        print(
            Printer.flatwrite(
                vms,
                order=[
                    "vagrant.name", "vbox.name", "vagrant.id",
                    "vagrant.provider", "vagrant.state", "vagrant.hostname"
                ],
                header=["name", "vbox", "id", "provider", "state",
                        "hostname"]))

    def test_10_create(self):
        HEADING()

        name = self.next_name()

        print("Name", name)

        self.p.create(
            name=self.name,
            image=self.image_name,
            size=self.size,
            # username as the keypair name based on
            # the key implementation logic
            ex_keyname=self.user,
            ex_security_groups=['default'])

        directory = Path(
            path_expand("~/.cloudmesh/vagrant/exp-grp-gregor-vm-1"))

        assert directory.is_dir()

        time.sleep(5)
        nodes = self.p.list()
        pprint(nodes)

        node = self.p.find(nodes, name=self.name)
        pprint(node)

        nodes = self.p.list(raw=False)
        for node in nodes:
            if node.name == self.name:
                self.testnode = node
                break

        assert node is not None