#!/usr/bin/env python3
import argparse
import os
from tabulate import tabulate
from virl2_client import ClientLibrary
def get_property(property: str):
path = os.path.expanduser("~")
virlrc = os.path.join(path, ".virlrc")
if os.path.isfile(virlrc):
with open(virlrc) as fh:
config = fh.readlines()
for line in config:
if line.startswith(property):
prop = line.split("=")[1].strip()
if prop.startswith('"') and prop.endswith('"'):
prop = prop[1:-1]
return prop
def get_nodes(args: argparse.ArgumentParser, cml: ClientLibrary):
data = []
index = 0
for lab in cml.all_labs():
for node in lab.nodes():
index += 1
if args.no == str(index):
if args.label != None:
node.label = args.label
if args.cpu != None:
node.cpus = int(args.cpu)
if args.ram != None:
node.ram = int(args.ram)
if args.x != None:
node.x = int(args.x)
if args.y != None:
node.y = int(args.y)
data.append(
[
index,
lab.title,
node.label,
node.node_definition,
node.cpus,
node.ram,
node.x,
node.y,
]
)
print(
tabulate(
data,
headers=["No", "Lab", "Node", "Definition", "CPU", "RAM", "X", "Y"],
)
)
def main():
parser = argparse.ArgumentParser(description="Adjust the position of the node.")
parser.add_argument("-n", "--no", help="Number")
parser.add_argument("-l", "--label", help="Label")
parser.add_argument("-c", "--cpu", help="CPUs")
parser.add_argument("-r", "--ram", help="RAM (MB)")
parser.add_argument("-x", help="X")
parser.add_argument("-y", help="Y")
args = parser.parse_args()
address = get_property("VIRL_HOST")
username = get_property("VIRL_USERNAME")
password = get_property("VIRL_PASSWORD")
verify = True
if get_property("CML_VERIFY_CERT").lower() == "false":
verify = False
cml = ClientLibrary(address, username, password, verify)
cml.is_system_ready(wait=True)
get_nodes(args, cml)
if __name__ == "__main__":
main()