def print_table(result, status=None, source=None, target=None):
        op_result = []
        for idx, i in enumerate(result):
            op_dict = dict()
            op_dict['idx'] = idx + 1
            op_dict['source'] = source
            op_dict['name'] = i['fileName']
            op_dict['size'] = i['contentLength']
            op_dict['lastmodified'] = i['lastModificationDate']
            op_dict['type'] = 'File'
            op_dict['status'] = status
            op_dict['target'] = target
            op_result.append(op_dict)

        # pprint(op_result)
        table = Printer.flatwrite(op_result,
                                  sort_keys=["idx"],
                                  order=[
                                      "idx", "source", "target", "name",
                                      "size", "type", "lastmodified", "status"
                                  ],
                                  header=[
                                      "S.No.", "Source CSP", "Target CSP",
                                      "Name", "Size", "Type", "Creation",
                                      "Status"
                                  ])
        print(table)
        return op_result
def table_test(self):
    table = Printer.flatwrite(self.data,
                              sort_keys=["name"],
                              order=["name", "address.city", "address.state"],
                              header=["Name", "City", "State"],
                              output='table')
    print(table)
Exemple #3
0
    def Print(self, data, output=None, kind=None):

        if output == "table":
            if kind == "secrule":
                # this is just a temporary fix, both in sec.py and here the
                # secgruops and secrules should be separated
                result = []
                for group in data:
                    # for rule in group['security_group_rules']:
                    #     rule['name'] = group['name']
                    result.append(group)
                data = result

            order = self.output[kind]['order']  # not pretty
            header = self.output[kind]['header']  # not pretty
            # humanize = self.output[kind]['humanize']  # not pretty

            print(
                Printer.flatwrite(
                    data,
                    sort_keys=["name"],
                    order=order,
                    header=header,
                    output=output,
                    # humanize=humanize
                ))
        else:
            print(Printer.write(data, output=output))
Exemple #4
0
    def test_list_vm(self):
        HEADING()
        vms = self.p.list()
        # pprint(vms)

        # TODO: bug th eprint function is not implemented
        # print (self.p.Print(vms, kind="vm"))

        # '''
        print(Printer.flatwrite(vms,
                                sort_keys=["name"],
                                order=["name",
                                       "state",
                                       "extra.properties.hardwareProfile.vmSize",
                                       "extra.properties.storageProfile.imageReference.sku",
                                       "extra.properties.storageProfile.osDisk.osType",
                                       "extra.properties.storageProfile.osDisk.diskSizeGB",
                                       "extra.properties.osProfile.adminUsername",
                                       "private_ips",
                                       "public_ips"],
                                header=["Name",
                                        "State",
                                        "vmSize",
                                        "Image",
                                        "OS Type",
                                        "Disk (GB)",
                                        "Admin User",
                                        "Private ips",
                                        "Public ips"])
              )
 def print_images(self):
     images = self.p.images()
     print(
         Printer.flatwrite(images,
                           sort_keys=["name"],
                           order=["name", "provider", "version"],
                           header=["Name", "Provider", "Version"]))
Exemple #6
0
 def key_selector(keys):
     '''
    This is a helper method for ssh key selection
    THIS IS JUST A SAFETY MEASURE, PLEASE DON'T MIND IT
     :param keys:
     :return:
     '''
     tmp_keys = keys[:]
     # indices = range(1,len(tmp_keys)+1)
     for key_idx, key in enumerate(keys):
         key['idx'] = key_idx + 1
     print(
         Printer.flatwrite(
             tmp_keys,
             sort_keys=["idx"],
             order=['idx', 'KeyName', 'KeyFingerprint'],
             header=['Index', 'Key Name', "Key Fingerprint"],
             output="table",
             humanize=None))
     # Console.msg("Please select one of the AWS key indices from the table above: ")
     picked = 0
     while picked < 1 or picked > len(keys):
         try:
             picked = int(
                 input(
                     "Please select one of the AWS key indices from the table above: "
                 ))
         except ValueError:
             pass
     return keys[picked - 1]
    def test_04_list_vm(self):
        HEADING()
        vms = self.p.list()
        pprint(vms)


        print(Printer.flatwrite(vms,
                                sort_keys=("name"),
                                order=["name",
                                       "state",
                                       "extra.task_state",
                                       "extra.vm_state",
                                       "extra.userId",
                                       "extra.key_name",
                                       "private_ips",
                                       "public_ips"],
                                header=["Name",
                                        "State",
                                        "Task state",
                                        "VM state",
                                        "User Id",
                                        "SSHKey",
                                        "Private ips",
                                        "Public ips"])
              )
    def Print(self, data, output=None):
        """
        print registry

        :param data:
        :param output:
        :return:
        """

        if output == "table":

            order = self.output[Registry.kind]['order']  # not pretty
            header = self.output[Registry.kind]['header']  # not pretty
            # humanize = self.output[kind]['humanize']  # not pretty

            print(
                Printer.flatwrite(
                    data,
                    sort_keys=["name"],
                    order=order,
                    header=header,
                    output=output,
                    # humanize=humanize
                ))
        else:
            print(Printer.write(data, output=output))
    def Print(self, data, output=None):
        """
        print output in a structured format

        :param data:  input data to be printed out
        :param output:  type of structured output
        :return:  structured output
        """

        if output == "table":

            order = self.output[RegistryPickle.kind]['order']  # not pretty
            header = self.output[RegistryPickle.kind]['header']  # not pretty
            # humanize = self.output[kind]['humanize']  # not pretty

            print(
                Printer.flatwrite(
                    data,
                    sort_keys=["name"],
                    order=order,
                    header=header,
                    output=output,
                    # humanize=humanize
                ))
        else:
            print(Printer.write(data, output=output))
Exemple #10
0
    def Print(self, data, kind=None, output="table"):
        """
        Print out the result dictionary as table(by default) or json.

        :param data: dic returned from volume functions
        :param kind: kind of provider
        :param output: "table" or "json"
        :return:
        """
        if kind is None and len(data) > 0:
            kind = data[0]["cm"]["kind"]
        if output == "table":
            order = self.provider.output[kind]['order']
            header = self.provider.output[kind]['header']
            if 'humanize' in self.provider.output[kind]:
                humanize = self.provider.output[kind]['humanize']
            else:
                humanize = None
            print(Printer.flatwrite(data,
                                    sort_keys=["name"],
                                    order=order,
                                    header=header,
                                    output=output,
                                    humanize=humanize)
                  )
        else:
            print(Printer.write(data, output=output))
    def Print(self, data, output=None, kind=None):
        # TODO: Joaquin

        if output == "table":
            if kind == "secrule":

                result = []
                for group in data:
                    for rule in group['security_group_rules']:
                        rule['name'] = group['name']
                        result.append(rule)
                data = result

            order = self.output[kind]['order']  # not pretty
            header = self.output[kind]['header']  # not pretty
            humanize = self.output[kind]['humanize']  # not pretty

            print(Printer.flatwrite(data,
                                    sort_keys=["name"],
                                    order=order,
                                    header=header,
                                    output=output,
                                    humanize=humanize)
                  )
        else:
            print(Printer.write(data, output=output))
Exemple #12
0
 def test_list_flavors(self):
     HEADING()
     flavors = self.p.flavors()
     print(
         Printer.flatwrite(flavors,
                           sort_keys=("name", "disk"),
                           order=["name", "id", "ram", "disk"],
                           header=["Name", "Id", "RAM", "Disk"]))
Exemple #13
0
 def test_list_images(self):
     HEADING()
     images = self.p.images()
     print(
         Printer.flatwrite(images,
                           sort_keys=("name"),
                           order=["name", "id", "driver"],
                           header=["Name", "Id", "Driver"]))
    def list(self,
             source=None,
             source_obj=None,
             target=None,
             target_obj=None,
             recursive=True):
        """
        To enlist content of "target object"
        :param source: source CSP - awss3/azure/local, None for list method
        :param source_obj: It can be file or folder, None for list method
        :param target: target CSP - awss3/azure/local
        :param target_obj: It can be file or folder
        :param recursive: enlist directories/sub-directories
        :return: dictionary enlisting objects
        """
        print("CALLING LOCAL PROVIDER'S LIST METHOD")
        # Storage local provider expects a path relative to the default
        # directory read from .yaml. Hence:
        if target_obj:
            target_path = Path(target_obj)
            relative_target = str(
                target_path.relative_to(*target_path.parts[:2]))
            # print("=======> ", relative_target)
        else:
            relative_target = '/'

        result = self.storage_provider.list(source=relative_target,
                                            recursive=recursive)

        op_result = []
        for idx, i in enumerate(result):
            op_dict = dict()
            op_dict['idx'] = idx + 1
            op_dict['CSP'] = target
            op_dict['name'] = i['name']
            op_dict['size'] = i['size']
            op_dict['created'] = i['creation']
            op_dict['type'] = 'File' if i['file'] is True else 'Dir'
            op_dict['source'] = source
            op_dict['target'] = target
            op_dict['status'] = 'Available'
            op_result.append(op_dict)

        # pprint(op_result)
        table = Printer.flatwrite(op_result,
                                  sort_keys=["idx"],
                                  order=[
                                      "idx", "source", "target", "name",
                                      "size", "type", "created", "status"
                                  ],
                                  header=[
                                      "S.No.", "Source CSP", "Target CSP",
                                      "Name", "Size", "Type", "Creation",
                                      "Status"
                                  ])
        print(table)
        return op_result
Exemple #15
0
 def test_001_print(self):
     HEADING()
     pprint(self.data)
     print(
         Printer.flatwrite(
             self.data,
             sort_keys=["name"],
             order=["name", "address.street", "address.city"],
             header=["Name", "Street", "City"],
         ))
 def Print(self, data, output=None, kind=None):
     order = self.output["volume"]['order']
     header = self.output["volume"]['header']
     print(Printer.flatwrite(data,
                             sort_keys=["name"],
                             order=order,
                             header=header,
                             output=output,
                             )
           )
Exemple #17
0
    def test_01_list_keys(self):
        HEADING()
        keys = self.p.keys()
        pprint(keys)

        print(
            Printer.flatwrite(keys,
                              sort_keys=("name"),
                              order=["name", "fingerprint"],
                              header=["Name", "Fingerprint"]))
Exemple #18
0
    def test_list_flavors(self):
        HEADING()
        flavors = self.p.flavors()
        # pprint (flavors)

        print(Printer.flatwrite(flavors,
                                sort_keys=["name", "vcpus", "disk"],
                                order=["name", "vcpus", "ram", "disk"],
                                header=["Name", "VCPUS", "RAM", "Disk"])
              )
Exemple #19
0
    def test_list_keys(self):
        HEADING()
        self.keys = self.p.keys()
        # pprint(self.keys)

        print(Printer.flatwrite(self.keys,
                                sort_keys=["name"],
                                order=["name", "fingerprint"],
                                header=["Name", "Fingerprint"])
              )
    def test_17_list_images(self):
        HEADING()
        images = self.p.images()
        pprint(images[:10])

        print(
            Printer.flatwrite(images[:10],
                              sort_keys=("id", "name"),
                              order=["name", "id", 'extra.os'],
                              header=["Name", "id", 'extra.os']))
        """
    def test_03_list_images(self):
        HEADING()
        images = self.p.images()
        # pprint(images)

        print(
            Printer.flatwrite(
                images,
                sort_keys=["name", "extra.minDisk"],
                order=["name", "extra.minDisk", "updated", "driver"],
                header=["Name", "MinDisk", "Updated", "Driver"]))
Exemple #22
0
    def test_list_keys(self):
        HEADING()
        Benchmark.Start()
        self.keys = provider.keys()
        Benchmark.Stop()
        # pprint(self.keys)

        print(Printer.flatwrite(self.keys,
                                sort_keys=["name"],
                                order=["name", "fingerprint"],
                                header=["Name", "Fingerprint"])
              )
Exemple #23
0
    def test_17_list_images(self):
        HEADING()
        images = self.p.images()
        pprint(images[:10])

        print(
            Printer.flatwrite(
                images[:10],
                sort_keys=("id", "name"),
                order=["name", "id", 'architecture', 'hypervisor'],
                header=["Name", "id", 'architecture', 'hypervisor']))
        """
    def test_06_list_images(self):
        HEADING()
        images = self.p.images()
        # pprint(images)
        sort_keys = self.p.p.output['image']['sort_keys']  # not pretty
        order = self.p.p.output['image']['order']  # not pretty
        header = self.p.p.output['image']['header']  # not pretty

        print(Printer.flatwrite(images,
                                sort_keys=sort_keys,
                                order=order,
                                header=header))
Exemple #25
0
    def test_03_list_flavors(self):
        HEADING()
        flavors = self.p.flavors()
        pprint(flavors)

        print(
            Printer.flatwrite(
                flavors,
                sort_keys=("name", "extra.cores", "extra.max_data_disks",
                           "price"),
                order=["name", "extra.cores", "extra.max_data_disks", "price"],
                header=["Name", "VCPUS", "max_data_disks", "Price"]))
        """
    def test_03_list_flavors(self):
        HEADING()
        flavors = self.p.flavors()
        #pprint(flavors)

        print(
            Printer.flatwrite(
                flavors,
                sort_keys=("name", "ram", "disk", "extra.numberOfCores",
                           "price"),
                order=["name", "ram", "disk", "extra.numberOfCores", "price"],
                header=["Name", "ram (MB)", "disk (GB)", "Cores", "price"]))
        """
    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_02_git(self):
        HEADING()
        config = Config()
        username = config["cloudmesh.profile.github"]
        print("Username:"******"name"),
                              order=["name", "fingerprint"],
                              header=["Name", "Fingerprint"]))

        assert len(keys) > 0
    def test_07_list_vm(self):
        HEADING()
        vms = self.p.list()
        # pprint (vms)

        sort_keys = self.p.p.output['vm']['sort_keys']  # not pretty
        order = self.p.p.output['vm']['order']  # not pretty
        header = self.p.p.output['vm']['header']  # not pretty

        print(Printer.flatwrite(vms,
                                sort_keys=sort_keys,
                                order=order,
                                header=header)
              )
Exemple #30
0
    def test_03_list_flavors(self):
        HEADING()
        flavors = self.p.flavors()
        pprint(flavors)

        print(
            Printer.flatwrite(
                flavors,
                sort_keys=("name", "extra.vcpu", "extra.memory", "price"),
                order=[
                    "name", "extra.vcpu", "extra.memory", "extra.clockSpeed",
                    "price"
                ],
                header=["Name", "VCPUS", "RAM", "Speed", "Price"]))
        """