def test_01_Name(self): HEADING() n = Name(experiment="exp", group="grp", user="******", kind="vm", counter=1) n.reset() assert n.counter == 1 print(n) assert str(n) == "exp-grp-gregor-vm-1" pprint(n.dict()) print(n.get("container")) print(n) assert str(n) == "exp-grp-gregor-container-1" n.incr() print(n) assert str(n) == "exp-grp-gregor-container-2" print(n.counter) assert n.counter == 2 m = Name() pprint(n.dict()) pprint(m.dict()) print(m) assert str(n) == str(m)
def new_name(self, experiment=None, group=None, user=None): """ Generate a VM name with the format `experiment-group-name-<counter>` where `counter` represents a running count of VMs created. Defaults can be modified in the cloudmesh4.yaml file. :param experiment: :param group: :param user: :return: The generated name. """ experiment = experiment or self.config["default"]["experiment"] group = group or self.config["default"]["group"] user = user or getpass.getuser() counter = Counter() count = counter.get() name = Name() name_format = { 'experiment': experiment, 'group': group, 'user': user, 'counter': count } name.set_schema('instance') counter.incr() return name.get(name_format)