Пример #1
0
    def detect(self):
        """

        :return:
        """
        banner("Detecting USB Card Reader")

        print("Make sure the USB Reader is removed ...")
        if not yn_choice("Is the reader removed?"):
            sys.exit()
        usb_out = set(Shell.execute("lsusb").splitlines())
        print("Now plug in the Reader ...")
        if not yn_choice("Is the reader plugged in?"):
            sys.exit()
        usb_in = set(Shell.execute("lsusb").splitlines())

        writer = usb_in - usb_out
        if len(writer) == 0:
            print(
                "ERROR: we did not detect the devise, make sure it is plugged."
            )
            sys.exit()
        else:
            banner("Detected Card Writer")

            print("\n".join(writer))
            print()
 def test_azure_list(self):
     HEADING()
     Benchmark.Start()
     Shell.execute("cms init", shell=True)
     Shell.execute("cms set cloud=azure", shell=True)
     list = Shell.execute("cms vm list --refresh", shell=True)
     Benchmark.Stop()
     VERBOSE(list)
    def run(self):
        result = Shell.execute('pwd')
        print(result)

        result = Shell.execute('ls', ["-l", "-a"])
        print(result)

        result = Shell.execute('ls', "-l -a")
        print(result)
Пример #4
0
    def test_list(self):
        HEADING()

        StopWatch.start("cms aws list")
        r1 = Shell.execute("cms aws list test_boot_01 --refresh", shell=True)
        r2 = Shell.execute("cms aws list test_boot_01", shell=True)
        StopWatch.stop("cms aws list")

        assert r1 == r2
Пример #5
0
    def test_frugal_azure(self):
        HEADING()

        Benchmark.Start()
        result = Shell.execute("cms frugal boot --cloud=azure", shell=True)
        result = Shell.execute("cms frugal benchmark", shell=True)
        Benchmark.Stop()

        VERBOSE('frugal benchmark aws complete')
        VERBOSE(result)
Пример #6
0
    def sampleShellExecute(self):
        """ function to use execute """
        from cloudmesh.common.Shell import Shell
        result = Shell.execute('pwd')
        print(result)

        result = Shell.execute('ls', ['-l', '-a'])
        print(result)

        result = Shell.execute('ls', '-l -a')
        print(result)
Пример #7
0
    def f(test):
        msg = "This is a test {test}".format(**locals())
        print("  jj   ", locals())
        from cloudmesh.common.debug import VERBOSE
        d = {'test': 'Gergor'}
        VERBOSE(d, "a", "RED", 100)
        from cloudmesh.common.console import Console

        msg = 'my message'

        Console.ok(msg)  # prins a green message
        Console.error(msg)  # prins a red message proceeded with ERROR
        Console.msg(msg)  # prins a regular black message

        from cloudmesh.common.variables import Variables

        variables = Variables()

        variables['debug'] = True
        variables['trace'] = True
        variables['verbose'] = 10
        m = {'key': 'value'}
        VERBOSE(m)
        a = {'p': "ac"}
        print(a['p'])

        from cloudmesh.common.Shell import Shell

        result = Shell.execute('pwd')
        print(result)

        result = Shell.execute('ls', ['-l', '-a'])
        print(result)

        result = Shell.execute('ls', '-l -a')
        print(result)

        result = Shell.ls('-aux')
        print(result)

        result = Shell.ls('-a')
        print(result)

        result = Shell.pwd()
        print(result)

        from cloudmesh.common.StopWatch import StopWatch
        from time import sleep

        StopWatch.start('test')
        sleep(1)
        StopWatch.stop('test')

        print(StopWatch.get('test'))
    def test_resume(self):
        HEADING()
        #Using 2 VMs to test_created usingn test_create* methods.
        vm_names = f"{self.vm_name_prefix}1,{self.vm_name_prefix}3"
        Shell.execute(f"cms multipass suspend {vm_names}", shell=True)
        Benchmark.Start()
        result = Shell.execute(f"cms multipass resume {vm_names}", shell=True)
        Benchmark.Stop()

        VERBOSE(result)

        assert 'Resumed' in result, "Error resuming instance"
        Benchmark.Status(True)
 def test_execute_list(self):
     if sys.platform != 'win32':
         HEADING()
         Benchmark.Start()
         r = Shell.execute('ls', ["-l", "-a"])
         Benchmark.Stop()
         print(r)
     else:
         HEADING()
         Benchmark.Start()
         r = Shell.execute('whoami', ["/user", "/fo", "table"])
         Benchmark.Stop()
         print(r)
Пример #10
0
 def test_execute_string(self):
     if sys.platform != 'win32':
         HEADING()
         Benchmark.Start()
         r = Shell.execute('ls', "-l -a")
         Benchmark.Stop()
         print(r)
     else:
         HEADING()
         Benchmark.Start()
         r = Shell.execute('whoami', "/user /fo table")
         Benchmark.Stop()
         print(r)
Пример #11
0
    def test_list(self):
        HEADING()

        Benchmark.Start()
        r1 = Shell.execute(
            f"cms vm list test_boot_01 --cloud={CLOUD} --output=table --refresh",
            shell=True)
        r2 = Shell.execute(
            f"cms vm list test_boot_01 --cloud={CLOUD} --output=table",
            shell=True)
        Benchmark.Stop()

        assert r1 == r2
Пример #12
0
    def write(self, filename=None):
        """
        Write the cmdline config to the specified filename
        """
        if filename is None:
            raise Exception("write called with no filename")
        if self.script is None:
            raise Exception("no script found. Did you run .get() first?")

        tmp_location = path_expand('~/.cloudmesh/cmburn/firstrun.sh.tmp')
        writefile(tmp_location, self.script)
        Shell.run(f'cat {tmp_location} | sudo tee {filename}')
        Shell.execute('rm', arguments=[tmp_location])
Пример #13
0
def main():
    vm_name = "tester-vm"
    Shell.execute("cms mongo admin start", shell=True)
    bench_marker = TestCompute()
    # bench_marker.test_cms_flavor_list()
    # bench_marker.test_cms_image_list()
    bench_marker.test_cms_vm_boot_one(vm_name)
    bench_marker.test_cms_vm_stop(vm_name)
    bench_marker.test_cms_vm_start(vm_name)
    bench_marker.test_cms_vm_terminate(vm_name, 1)
    bench_marker.test_cms_vm_list()

    # output into csv file, look for "benchmark_result.csv
    bench_marker.csv_writer()
Пример #14
0
    def test_03_delete(self):
        HEADING()

        while 'pending' in Shell.execute("cms vm list test_boot_02 --refresh",
                                         shell=True):
            time.sleep(1)

        Benchmark.Start()
        result = Shell.execute("cms vm delete test_boot_02", shell=True)
        Benchmark.Stop()

        VERBOSE(result)

        assert "test_boot_02" in result
Пример #15
0
 def test_base(self, command):
     time_record = {}
     for cloud_provider in self.cloud_providers:
         Shell.execute("cms set cloud=" + cloud_provider, shell=True)
         print("Working on "+cloud_provider)
         if cloud_provider in ["azure", "aws"]:
             if "image" in command or "flavor" in command:
                 print("This will take some time")
         start = time()
         result = Shell.execute(command, shell=True)
         print(result)
         end = time()
         res = end - start
         time_record.update({cloud_provider: res})
     return time_record
Пример #16
0
    def do_usb(self, args, arguments):
        """
        ::

          Usage:
                usb list
                usb plist
                usb ioreg

          This command does some useful things.

          Arguments:
              FILE   a file name

          Options:
              -f      specify the file

        """
        print(arguments)

        if arguments.list:

            r = Shell.execute('system_profiler', 'SPUSBDataType')
            r = r.replace("\n\n", "\n")
            r = r.replace("        iBridge:", "      iBridge:")
            print(r)

            # d = yaml.load(r)

            # d = json.loads(r)

            # pprint(d)

        elif arguments.plist:

            r = Shell.execute('system_profiler', ["-xml", 'SPUSBDataType'])

            pprint(plistlib.loads(r))

        elif arguments.ioreg:

            # r = Shell.execute('ioreg', ["-p", "IOSUP", "-w0", "-l"])
            # r = Shell.execute('ioreg', ["-p", "IOSUP", "-w0", "-l"])

            r = Shell.execute("ioreg", ["-p", "IOUSB", "-b", "-n", "USB2.0-Serial"])
            print(r)

            print(r)
Пример #17
0
    def test_cms_help(self):
        HEADING()

        Benchmark.Start()
        result = Shell.execute("cms help", shell=True)
        Benchmark.Stop()
        VERBOSE(result)
Пример #18
0
    def list_os(self):
        """
        :return: the dict with the new name
        """

        result = Shell.execute(self.vboxmanage + " list ostypes", shell=True)

        data = {}

        result = result.split("\n\n")
        entries = {}

        id = "None"
        for element in result:
            attributes = element.split("\n")
            for a in attributes:

                attribute, value = a.split(":")
                value = value.strip()
                attribute = attribute.lower()
                attribute = attribute.replace(" ", "_")
                print(">>>>", attribute, value)
                if attribute == "id":
                    id = value
                    entries[id] = {}
                entries[id][attribute] = value

        return entries
Пример #19
0
    def images(self):
        def convert(data_line):
            data_line = data_line.replace("(", ",")
            data_line = data_line.replace(")", ",")
            data_entry = data_line.split(",")
            data = dotdict()
            data.name = data_entry[0].strip()
            data.provider = data_entry[1].strip()
            data.version = data_entry[2].strip()
            data = self.update_dict(data, kind="image")
            return data

        result = Shell.execute("vagrant box list", shell=True)

        if "There are no installed boxes" in result:
            return None
        else:
            result = result.split("\n")
        lines = []
        for line in result:
            entry = convert(line)
            if "date" in entry:
                date = entry["date"]
            lines.append(entry)

        return lines
Пример #20
0
    def boot(self, **kwargs):

        arg = dotdict(kwargs)
        arg.cwd = kwargs.get("cwd", None)

        # get the dir based on name

        print("ARG")
        pprint(arg)
        vms = self.to_dict(self.nodes())

        print("VMS", vms)

        arg = self._get_specification(**kwargs)

        pprint(arg)

        if arg.name in vms:
            Console.error("vm {name} already booted".format(**arg),
                          traceflag=False)
            return None

        else:
            self.create(**kwargs)
            Console.ok("{name} created".format(**arg))
            Console.ok("{directory}/{name} booting ...".format(**arg))

            result = Shell.execute("vagrant", ["up", arg.name],
                                   cwd=arg.directory)
            Console.ok("{name} ok.".format(**arg))

            return result
Пример #21
0
    def list_images(cls):
        def convert(data_line):
            data_line = data_line.replace("(", "")
            data_line = data_line.replace(")", "")
            data_line = data_line.replace(",", "")
            data_entry = data_line.split(" ")
            data = dotdict()
            data.name = data_entry[0]
            data.provider = data_entry[1]
            data.date = data_entry[2]
            return data

        result = Shell.execute("vagrant", ["box", "list"])

        if "There are no installed boxes" in result:
            return None
        else:
            result = result.splitlines()
        lines = []
        for line in result:
            entry = convert(line)
            if "date" in entry:
                date = entry["date"]
                # "20181203.0.1"
                entry["date"] = datetime.strptime(date, '%Y%m%d.%H.%M')
            lines.append(entry)

        return lines
Пример #22
0
    def list(cls, verbose=False):
        def convert(line):
            entry = (' '.join(line.split())).split(' ')
            data = dotdict()
            data.id = entry[0]
            data.name = entry[1]
            data.provider = entry[2]
            data.state = entry[3]
            data.directory = entry[4]

            return data

        result = Shell.execute("vagrant", "global-status --prune")
        if verbose:
            print(result)
        if "There are no active" in result:
            return None

        lines = []
        for line in result.split("\n")[2:]:
            if line == " ":
                break
            else:
                lines.append(convert(line))
        return lines
Пример #23
0
 def test_info(self):
     HEADING()
     Benchmark.Start()
     result = Shell.execute("cms multipass info", shell=True)
     Benchmark.Stop()
     VERBOSE(result)
     assert result != None, "result cannot be null"
Пример #24
0
    def check_passphrase(self):
        """
        this does not work with pem

        cecks if the ssh key has a password
        :return:
        """

        self.data["passphrase"] = getpass("Passphrase:")

        if self.data.passphrase is None or self.data.passphrase == "":
            Console.error("No passphrase specified.")
            raise ValueError('No passphrase specified.')

        try:
            command = "ssh-keygen -p -P {passphrase} -N {passphrase} -f {key}".format(
                **self.data)
            r = Shell.execute(command, shell=True, traceflag=False)

            if "Your identification has been saved with the new passphrase." in r:
                Console.ok("Password ok.")
                return True
        except:
            Console.error("Password not correct.")

        return False
Пример #25
0
    def nodes(self, verbose=False):
        """
        list all nodes id

        :return: an array of dicts representing the nodes
        """
        def convert(data_line):

            entry = (' '.join(data_line.split())).split(' ')
            data = dotdict()
            data.id = entry[0]
            data.name = entry[1]
            data.provider = entry[2]
            data.state = entry[3]
            data.directory = entry[4]
            return data

        result = Shell.execute("vagrant", "global-status --prune")
        if verbose:
            print(result)
        if "There are no active" in result:
            return None

        lines = []
        for line in result.splitlines()[2:]:
            if line == " ":
                break
            else:
                lines.append(convert(line))
        return lines
Пример #26
0
    def info(self, name=None):
        """
        gets the information of a node with a given name

        :param name:
        :return: The dict representing the node including updated status
        """

        arg = dotdict()
        arg.name = name
        config = Config()

        cloud = "vagrant"  # TODO: must come through parameter or set cloud
        arg.path = config.data["cloudmesh"]["cloud"]["vagrant"]["default"][
            "path"]
        arg.directory = os.path.expanduser("{path}/{name}".format(**arg))

        result = Shell.execute("vagrant", ["ssh-config"], cwd=arg.directory)
        lines = result.split("\n")
        data = {}
        for line in lines:
            attribute, value = line.strip().split(" ", 1)
            if attribute == "IdentityFile":
                value = value.replace('"', '')

            data[attribute] = value
        return data
Пример #27
0
    def do_brian(self, args, arguments):
        """
        ::

          Usage:
                brian --file=FILE

          This command does some useful things.

          Arguments:
              FILE   a file name

          Options:
              -f      specify the file

        """
        arguments.FILE = arguments['--file'] or None

        VERBOSE(arguments)

        if arguments.FILE:
            result = Shell.execute('grep', ['-i', 'brian', arguments.FILE])
            print(result)
        else:
            Console.error("provide a file")

        return ""
Пример #28
0
    def images(self):
        def convert(data_line):
            data_line = data_line.replace("(", ",")
            data_line = data_line.replace(")", ",")
            data_entry = data_line.split(",")
            data = dotdict()
            data.name = data_entry[0].strip()
            data.provider = data_entry[1].strip()
            data.version = data_entry[2].strip()
            return data

        result = Shell.execute("vagrant box list", shell=True)

        if "There are no installed boxes" in result:
            return None
        else:
            result = result.split("\n")
        lines = []
        for line in result:
            entry = convert(line)
            if "date" in entry:
                date = entry["date"]
                # "20181203.0.1"
                #entry["date"] = datetime.strptime(date, '%Y%m%d.%H.%M')
            lines.append(entry)

        return lines
Пример #29
0
    def test_stop(self):
        HEADING()

        Benchmark.Start()
        result = Shell.execute(f"cms openapi server stop {name}", shell=True)
        Benchmark.Stop()
        VERBOSE(result)
Пример #30
0
    def put(self, storage_provider, storage_bucket_name, args):
        '''Sets lifecycle configuration rules for your bucket. If a 
            lifecycle configuration exists, it replaces it.
   
        :param storage_provider: Name of the cloud service provider
        :param storage_bucket_name: Name of the storage bucket
        :exception: Exception
        :returns: Result of operation as string
        '''

        try:
            # Load config file
            config_file = self.load_config_files(args)

            # Invoke GCP gsutil via CMS command shell
            result = Shell.execute(self.SERVICE_CLI, [
                self.SERVICE_COMMAND_LIFECYCLE, self.SERVICE_SUBCOMMAND_SET,
                config_file, self.STORAGE_BUCKET_PROTOCOL + storage_bucket_name
            ])

            # Cleanup
            if (args.expiry_in_days):
                os.remove(config_file)

            # Debug
            Console.ok(result)

        except Exception as error:
            Console.error(error, prefix=True, traceflag=True)

        return result