Exemple #1
0
def ls(all, all_users):
    """
    lists running labs and optionally those in the cache
    """
    server = VIRLServer()
    client = get_cml_client(server)
    labs = []
    cached_labs = None

    lab_ids = client.get_lab_list(all_users)
    for id in lab_ids:
        labs.append(client.join_existing_lab(id))

    if all:
        cached_labs = []
        cache_root = get_cache_root()
        if os.path.isdir(cache_root):
            for f in os.listdir(cache_root):
                lab_id = f
                cached_labs.append(CachedLab(lab_id, cache_root + "/" + f))

    try:
        pl = ViewerPlugin(viewer="lab")
        pl.visualize(labs=labs, cached_labs=cached_labs)
    except NoPluginError:
        lab_list_table(labs, cached_labs)
Exemple #2
0
def get_lab_title(fname):
    """
    Try and obtain a sensible title for the lab based on the filename
    and/or its contents.
    """
    # We need to do this to preserve any .virl extension to to tell CML this
    # is an older file.
    title = os.path.basename(fname)
    if not fname.lower().endswith(".virl"):
        title = os.path.splitext(fname)[0]
        # Load the lab YAML to try and extract its title property
        try:
            lab_stub = CachedLab("bogusid", fname)
        except Exception:
            # Someone may be trying to load a 1.x file without the .virl extension.
            click.secho(
                "File {} does not appear to be a YAML-formatted CML topology file."
                "If this is a CML/VIRL 1.x file, it must end with '.virl'".
                format(fname),
                fg="red",
            )
            exit(1)
        else:
            title = lab_stub.title

    return title
Exemple #3
0
def ls(all, **kwargs):
    """
    lists running labs and optionally those in the cache
    """
    server = VIRLServer()
    client = get_cml_client(server)
    labs = []
    cached_labs = None

    lab_ids = client.get_lab_list()
    for id in lab_ids:
        labs.append(client.join_existing_lab(id))

    if all:
        cached_labs = []
        cache_root = get_cache_root()
        if os.path.isdir(cache_root):
            for f in os.listdir(cache_root):
                lab_id = f
                cached_labs.append(CachedLab(lab_id, cache_root + "/" + f))

    lab_list_table(labs, cached_labs)
Exemple #4
0
def lid():
    """
    get the current lab title and ID
    """
    server = VIRLServer()
    client = get_cml_client(server)
    current_lab = get_current_lab()
    if current_lab:
        lab = safe_join_existing_lab(current_lab, client)
        # The lab really should be on the server.
        if not lab:
            try:
                lab = CachedLab(current_lab, get_current_lab_link())
            except Exception:
                pass

        if lab:
            click.echo("{} (ID: {})".format(lab.title, current_lab))
        else:
            click.secho(
                "Current lab is set to {}, but is not on server or in cache!".
                format(current_lab),
                fg="red")