def test_001_read(self): HEADING("test if cloudmesh.yaml is loaded") d = ConfigDict("cloudmesh.yaml", verbose=True) assert d["cloudmesh"]["profile"]["firstname"] != "" assert len(d["cloudmesh"]["clouds"]) > 0 """
def test_004_yaml(self): HEADING("test if yaml is produced") d = ConfigDict("cloudmesh.yaml", verbose=True) result = d.yaml try: assert result.startswith("meta") except Exception as e: print("not valid yaml file.") assert False
def test_003_json(self): HEADING("test if json is produced") d = ConfigDict("cloudmesh.yaml", verbose=True) assert d.json.startswith('{') try: assert not isinstance(d.json, str) print("json should be string") assert False except Exception as e: assert isinstance(d.json, str)
def test__config(self): #test original yaml file configDict = ConfigDict(path_expand("~/.cloudmesh/cloudmesh.yaml")) assert configDict.__getitem__("meta.version") #test tmp_yaml file configDict = ConfigDict(path_expand("~/.cloudmesh/tmp/cloudmesh.yaml")) assert configDict.__getitem__("meta.version") # test enc_yaml file with pytest.raises(UnicodeDecodeError) as e: con = Config(path_expand("~/.cloudmesh/tmp/cloudmesh.yaml.enc")) assert con # test dec_yaml file config = Config(config_path="~/.cloudmesh/cloudmesh.yaml.enc") assert configDict.__getitem__("meta.version")
config_ssh.write(entry) config_ssh.close() self.load() if verbose: Console.ok("Added india to ~/.ssh/config") except Exception as e: if verbose: Console.error(e.message) if __name__ == "__main__": from cloudmesh.common.ConfigDict import ConfigDict hosts = ssh_config() user = ConfigDict("cloudmesh.yaml")["cloudmesh.profile.user"] print("User:"******"india", username=user) print(hosts.filename) print(hosts.list()) print(hosts) import sys sys.exit() r = hosts.execute("india", "hostname") print(r)
def set(self, filename, key, value): configDict = ConfigDict(filename) configDict[key] = value
def do_swarm(self, args, arguments): """ :: Usage: swarm host list swarm host delete ADDR swarm host install HFILE swarm host NAME ADDR swarm benchmark N swarm create [ARG...] swarm join ADDR TYPE [ARG...] swarm leave [ARG...] swarm network create NAME [ARG...] swarm network list [ARG...] swarm network refresh swarm network delete NAME swarm service create NAME IMAGE [ARG...] swarm service list [ARG...] swarm service delete NAME swarm service refresh swarm node list swarm node refresh swarm image refresh swarm image list [ARG...] swarm container refresh swarm container list [ARG...] Arguments: NAME The name of the docker swarm IMAGE Docker server images HFILE Ansible Inventory.txt to be used N Number of Benchmark iterations ADDR Address of host ip:port(if port no given default port is assumed) TYPE Whether the node is Manager or Worker URL URL of docker API [ARG..] Denotes a extensible arguments that can be passed as a name value pair.Swarm Services and networks have a lot of customization options.These options are documented here http://docker-py.readthedocs.io/en/stable/index.html All the options are available by simply passing the values as a name value pair eg swarm service create NAME IMAGE hostname=?? networks=?? Options: -v verbose mode Description: Manages a virtual docker swarm on a cloud """ kwargs = {} if arguments.ARG: for j in arguments.ARG: kwargs[j.split('=', 1)[0].strip()] = j.split('=', 1)[1].strip() val = j.split('=', 1)[1].strip() print(val) if '[' in j.split('=', 1)[1].strip(): val = val.replace('[', '').replace(']', '').split(',') kwargs[j.split('=', 1)[0].strip()] = val stopwatch = StopWatch() stopwatch.start('E2E') Base = ConfigDict('cloudmesh_cmd5.yaml', verbose=False) if arguments.benchmark: path = Base['cloudmesh']['config']['base'] os.chdir(path + 'benchmark') command = 'python run_benchmark.py swarm_all.csv ' + arguments.N print(command) os.system(command) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.host and arguments.install: if arguments.HFILE: hosts = arguments.HFILE else: hosts = 'hosts' path = Base['cloudmesh']['config']['base'] os.chdir(path + 'scripts') command = 'python run_script.py docker-server-setup.cms ' + hosts print(command) os.system(command) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return os.environ["DOCKER_HOST"] = Base['cloudmesh']['container']['docker'][ 'work']['host'] if arguments.host and arguments.list: swarm = Swarm(os.environ["DOCKER_HOST"]) swarm.host_list() stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.host and arguments.delete: swarm = Swarm(os.environ["DOCKER_HOST"]) swarm.host_delete("{ADDR}".format(**arguments)) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.host: swarm = Swarm("{ADDR}".format(**arguments)) swarm.host_create("{ADDR}".format(**arguments), "{NAME}".format(**arguments)) stopwatch.stop('E2E') Base['cloudmesh']['container']['docker']['work'][ 'host'] = "{ADDR}".format(**arguments) Base.save() print('Time Taken:' + str(stopwatch.get('E2E'))) return swarm = Swarm(os.environ["DOCKER_HOST"]) if arguments.network and arguments.create and arguments.NAME: swarm.network_create("{NAME}".format(**arguments), kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.create and not (arguments.service): swarm.create(kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.leave: swarm.leave(kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.join and arguments.ADDR and arguments.TYPE: swarm.join("{ADDR}".format(**arguments), "{TYPE}".format(**arguments), kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.service and arguments.create: swarm.service_create("{NAME}".format(**arguments), "{IMAGE}".format(**arguments), kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.service and arguments.list: swarm.service_list(kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.service and arguments.refresh: swarm.service_refresh(kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.service and arguments.delete: swarm.service_delete("{NAME}".format(**arguments)) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.node and arguments.list: swarm.node_list(kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.node and arguments.refresh: swarm.node_refresh() stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.network and arguments.list: swarm.network_list(kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.network and arguments.refresh: swarm.network_refresh(kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.image and arguments.list: swarm.images_list(kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.image and arguments.refresh: swarm.images_refresh(kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.container and arguments.list: swarm.container_list(kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.container and arguments.refresh: swarm.container_refresh(kwargs) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return if arguments.network and arguments.delete: swarm.network_delete("{NAME}".format(**arguments)) stopwatch.stop('E2E') print('Time Taken:' + str(stopwatch.get('E2E'))) return