Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def list(self):
"""List the Drbd volumes and statuses"""
# Set permissions as having been checked, as listing VMs
# does not require permissions
self._get_registered_object('auth').set_permission_asserted()
# Create table and add headers
table = Texttable()
table.set_deco(Texttable.HEADER | Texttable.VLINES)
table.header(('Name', 'Type', 'Location', 'Nodes', 'Shared', 'Free Space'))
# Set column alignment and widths
table.set_cols_width((15, 5, 30, 70, 6, 9))
table.set_cols_align(('l', 'l', 'l', 'l', 'l', 'l'))
for storage_backend in self.get_all():
table.add_row((
storage_backend.name,
storage_backend.storage_type,
storage_backend.get_location(),
', '.join(storage_backend.nodes),
str(storage_backend.shared),
SizeConverter(storage_backend.get_free_space()).to_string()
))
return table.draw()
@Expose()
def listVms(self, include_ram=False, include_cpu=False, include_disk=False):
"""Lists the VMs that are currently on the host"""
table = Texttable()
table.set_deco(Texttable.HEADER | Texttable.VLINES)
headers = ['VM Name', 'State', 'Node']
if include_ram:
headers.append('RAM Allocation')
if include_cpu:
headers.append('CPU')
if include_disk:
headers.append('Total disk size (MiB)')
table.header(tuple(headers))
for vm_object in sorted(self.getAllVirtualMachines(), key=lambda vm: vm.name):
vm_row = [vm_object.get_name(), vm_object._getPowerState().name,
vm_object.getNode() or 'Unregistered']
if include_ram:
vm_row.append(str(int(vm_object.getRAM()) / 1024) + 'MB')
if include_cpu:
for f in input_to_cmd:
if os.path.isdir(f):
files.extend(list_files(f, file_filter=file_filter))
elif file_filter(f):
files.append(f)
else:
for f in input_to_cmd:
if os.path.isdir(f):
raise Exception('Directory provided without recursive')
files = input_to_cmd
results = rename_process(template, files, index_start, output, regex,
ignore_missing_regex=ignore_missing_regex)
if ns['dry_run']:
t = Texttable(max_width=0)
t.set_deco(Texttable.VLINES | Texttable.HEADER)
t.add_rows([('Source', 'Destination')] + results)
print(t.draw())
else:
for src, dest in results:
d = os.path.dirname(dest)
if d:
os.makedirs(d, exist_ok=True)
self._move(src, dest)
def _has_vlines(self):
"""Return a boolean, if vlines are required or not
"""
return self._deco & Texttable.VLINES > 0
@Expose()
def print_info(self):
"""Print information about the nodes in the cluster."""
table = Texttable()
table.set_deco(Texttable.HEADER | Texttable.VLINES)
table.header(('Node', 'IP Address', 'Status', 'CPU Usage', 'Memory Usage'))
# Add this node to the table
table.add_row((
get_hostname(),
self.get_cluster_ip_address(),
'Local',
self.po__get_registered_object('host_statistics').get_cpu_usage_string(),
self.po__get_registered_object('host_statistics').get_memory_usage_string()))
# Add remote nodes
for node in self.get_nodes(return_all=True):
node_config = self.get_node_config(node)
node_status = 'Unreachable'
cpu = ''
ram = ''
try:
Returns:
str: Record data in long format.
"""
title = util.hline(self.title_fmt % {'model_name': records[0].name.capitalize(),
'storage_path': records[0].storage}, 'cyan')
retval = [title]
for record in records:
rows = [['Attribute', 'Value', 'Command Flag', 'Description']]
populated = record.populate()
for key, val in sorted(populated.iteritems()):
if key != self.model.key_attribute:
rows.append(self._format_long_item(key, val))
table = Texttable(logger.LINE_WIDTH)
table.set_cols_align(['r', 'c', 'l', 'l'])
table.set_deco(Texttable.HEADER | Texttable.VLINES)
table.add_rows(rows)
retval.append(util.hline(populated[self.model.key_attribute], 'cyan'))
retval.extend([table.draw(), ''])
return retval
total_o += o_size
sum_percent += percent
table.append([name, sizeof_fmt(i_size), sizeof_fmt(o_size), _f_percent(percent)])
else:
not_converted.append(name)
if count > 0:
table.append(['', '', '', ''])
per = total_o / float(total_i) * 100
table.append(['Total', sizeof_fmt(total_i), sizeof_fmt(total_o), _f_percent(per)])
avg = sum_percent / count
table.append(['Average', '', '', _f_percent(avg)])
t = Texttable(max_width=0)
t.set_deco(Texttable.VLINES | Texttable.HEADER)
t.set_cols_align(['l', 'r', 'r', 'r'])
t.add_rows(table)
print(t.draw())
print('{} Larger than original'.format(len(bigger)))
for i, o, i_size, o_size, percent in bigger:
print('{}: {} -> {} ({:.2f}%)'.format(i, sizeof_fmt(i_size), sizeof_fmt(o_size),
percent))
if len(not_converted) > 0:
print('Not Converted:')
for i in not_converted:
print(' {}'.format(i))