Exemple #1
0
 def temp_list(self, args):
     templates_service = self.c.system_service().templates_service()
     try:
         if args.prefix is not None:
             search_prefix = 'name=' + args.prefix + '*'
         else:
             search_prefix = '*'
         templates = templates_service.list(search=search_prefix)
         rows = []
         for template in templates:
             cores = template.cpu.topology.cores * template.cpu.topology.sockets * template.cpu.topology.threads
             memory = template.memory / 1024 / 1024
             description = ""
             if template.description is not None:
                 description = template.description
             rows.append([
                 template.id, template.name,
                 str(memory) + ' M', cores,
                 str(description)
             ])
         output = Output(["ID", "Name", "Mem", "CPU", "Description"], rows)
         output.print_table()
         self.c.close()
     except sdk.Error as err:
         print "Failed to list templates, %s" % str(err)
Exemple #2
0
    def vm_show(self, args):
        vms_service = self.c.system_service().vms_service()
        try:
            rows = []

            vm = vms_service.list(search=args.vm_name)[0]
            vm_service = vms_service.vm_service(vm.id)
            # Print basic information
            rows.append(["Name", vm.name])
            rows.append(["ID", vm.id])
            rows.append(["Status", str(vm.status).upper()])
            rows.append(["Memory", str(vm.memory / 1024 / 1024) + 'M'])
            rows.append([
                "CPU", vm.cpu.topology.cores * vm.cpu.topology.sockets *
                vm.cpu.topology.threads
            ])
            # Print Disk information
            disk_attachments_service = vm_service.disk_attachments_service()
            disk_attachments = disk_attachments_service.list()
            for disk_attachment in disk_attachments:
                disk = self.c.follow_link(disk_attachment.disk)
                rows.append([
                    "Disks",
                    [
                        disk.name, disk.id,
                        str(disk.provisioned_size / 1024 / 1024 / 1024) + 'G'
                    ]
                ])

            # We use nics_service() instead of reported_devices_service()
            # because we need to get NIC id and name
            nics_service = vm_service.nics_service().list()
            for nic in nics_service:
                for device in nic.reported_devices:
                    if device.ips is not None:
                        for ip in device.ips:
                            if ip.version.value == 'v4':
                                rows.append([
                                    "Active Nics",
                                    [
                                        nic.name, nic.mac.address, nic.id,
                                        ip.address
                                    ]
                                ])
                    if device.ips is None:
                        rows.append([
                            "Inactive Nics",
                            [nic.name, nic.mac.address, nic.id]
                        ])

            output = Output(["Item", "Value"], rows)
            output.print_table()
        except sdk.Error as err:
            print str(err)
        except IndexError:
            print "Error: No such VM %s" % args.vm_name
Exemple #3
0
 def net_list(self, args):
     networks_service = self.c.system_service().networks_service()
     try:
         networks = networks_service.list()
         rows = []
         for network in networks:
             comment = ""
             description = ""
             if network.description is not None:
                 description = network.description
             if network.comment is not None:
                 comment = network.comment
             rows.append([network.id, network.name, comment, description])
         output = Output(["ID", "Name", "Comment", "Description"], rows)
         output.print_table()
         self.c.close()
     except sdk.Error as err:
         print "Failed to list networks, %s" % str(err)
Exemple #4
0
 def sd_list(self, args):
     try:
         sds_service = self.c.system_service().storage_domains_service()
         rows = []
         for sd in sds_service.list():
             if sd.available is not None and sd.used is not None:
                 rows.append([
                     sd.id, sd.name, sd.storage.type,
                     str((sd.available + sd.used) / 1024 / 1024 / 1024) +
                     'G',
                     str(sd.available / 1024 / 1024 / 1024) + 'G'
                 ])
             else:
                 rows.append(
                     [sd.id, sd.name, sd.storage.type, "N/A", "N/A"])
         output = Output(["ID", "Name", "Type", "Total", "Free"], rows)
         output.print_table()
     except sdk.Error as err:
         print "Failed to list disks, %s" % str(err)
Exemple #5
0
 def vm_list(self, args):
     # Call ovirtsdk to get vms_service
     vms_service = self.c.system_service().vms_service()
     # We check whether prefix has been given or not
     if args.prefix is not None:
         search_prefix = 'name=' + args.prefix + '*'
     else:
         search_prefix = 'name=' + environ.get('TITAMU_VM_PREFIX') + '*'
     try:
         # Get vm list by using vms_service
         vms = vms_service.list(
             search=search_prefix,
             case_sensitive=False,
         )
         rows = []
         for vm in vms:
             addr = ""
             comment = ""
             if vm.comment is not None:
                 comment = vm.comment
             vm_service = vms_service.vm_service(vm.id)
             # We use reported_devices_service method to get all the
             # NICs that have IP address assigned
             for device in vm_service.reported_devices_service().list():
                 if device.ips is not None and vm.status.value == 'up':
                     for ip in device.ips:
                         # cchen: ip.version is a enum so we have to use "value" to
                         # get its real value we are assuming that only the IP which
                         # starts with '10' is something that we are interested in
                         if ip.version.value == 'v4' and ip.address.startswith(
                                 '10'):
                             addr += ip.address + '  '
             rows.append(
                 [vm.id, vm.name,
                  vm.status.value.upper(), addr, comment])
         output = Output(["ID", "Name", "Status", "Networks", "Comment"],
                         rows)
         output.print_table()
         self.c.close()
     except sdk.Error as err:
         print "Failed to list VMs, %s" % str(err)
Exemple #6
0
    def disk_list(self, args):
        try:
            vms_service = self.c.system_service().vms_service()
            vm = vms_service.list(search=args.vm_name)[0]
            vm_service = vms_service.vm_service(vm.id)
            disk_attachments_service = vm_service.disk_attachments_service()
            disk_attachments = disk_attachments_service.list()
            rows = []
            for disk_attachment in disk_attachments:
                disk = self.c.follow_link(disk_attachment.disk)
                rows.append([
                    disk.id, disk.name,
                    str(disk.provisioned_size / 1024 / 1024 / 1024) + "G",
                    str(disk.status).upper()
                ])

            output = Output(["ID", "Name", "Size", "Status"], rows)
            output.print_table()
            self.c.close()
        except sdk.Error as err:
            print "Failed to list disks, %s" % str(err)