Example #1
0
def deploy_app(device_id, app_id, app_version):
    """Create task to deploy application."""
    kargs={'host': c.cfg['host'], "api_version": c.cfg['api_version'], "url_path": "/applications"}
    versions = esapp.App(kargs).get_app_version_by_id(app_id)

    kargs.update({"url_path": "/tasks"})
    if not app_version in versions:
        sys.exit("Fail: app_version \"%s\" not found, available list:%s" \
            %(str(app_version), str(jsn.dumps(versions))))

    task = estask.Task(kargs)
    try:
        dict_resp= task.create_app_task(device_id, app_version, app_id)
    except Exception as e:
        sys.exit("Fail:  %s" %str(e))

    if dict_resp == None:
        sys.exit("Fail: error response")

    try:
        click.echo("Success to create a task id: %s" %(str(dict_resp["task_id"])))
    except Exception as e:
        sys.exit("Fail: %s %s" %(str(e), str(dict_resp)))

    if 'status' in dict_resp and dict_resp['status'].lower() != 'success':
        sys.exit(1)
Example #2
0
File: mix.py Project: NXP/escli
def list(json):
    """Show your query list"""

    kargs = {
        'host': c.cfg['host'],
        "api_version": c.cfg['api_version'],
        "url_path": "/applications"
    }
    app = esapp.App(kargs)
    try:
        dict_resp = app.get_registry()
    except Exception as e:
        sys.exit("failed to query registry:  %s" % str(e))

    if dict_resp == None:
        click.echo("fail to get registry list")
        sys.exit(1)

    if json:
        print(jsn.dumps(dict_resp, sort_keys=True, indent=4))
        return
    try:
        app.print_registry(dict_resp)
    except Exception as e:
        sys.exit("failed to query registry:  %s" % str(e))
Example #3
0
def deploy(device_id, app_id, app_version, hostnet):
    """Deploy one application to device"""

    kargs = {
        'host': c.cfg['host'],
        "api_version": c.cfg['api_version'],
        "url_path": "/deployment/applications"
    }

    if device_id is None:
        click.echo("A device ID is needed.")
        sys.exit(1)

    if app_id is None:
        click.echo("A application ID is needed.")
        sys.exit(1)

    app = esapp.App(kargs)
    try:
        dict_resp = app.deploy_app_to_device(device_id, app_id, hostnet,
                                             app_version)
    except Exception as e:
        sys.exit("failed to deploy applications:  %s" % str(e))

    if dict_resp == None:
        sys.exit("failed to deploy application")

    try:
        click.echo("Success to deploy instance %s" %
                   dict_resp['metadata']['name'])
    except Exception:
        click.echo("Success to deploy instance %s" %
                   dict_resp['items'][0]['metadata']['name'])
Example #4
0
def list(ctx, id, limit, offset, json, max_width):
    """List your Applications"""

    if id != None:
        return ctx.invoke(show, id=id)

    kargs = {
        'host': c.cfg['host'],
        "api_version": c.cfg['api_version'],
        "url_path": "/applications"
    }
    kargs['params'] = {"limit": limit, "offset": offset}
    app = esapp.App(kargs)
    try:
        dict_resp = app.query_apps()
    except Exception as e:
        sys.exit("failed to query applications:  %s" % str(e))

    if dict_resp == None:
        click.echo("fail to get application list")
        sys.exit(1)

    if not 'applications' in dict_resp:
        sys.exit("error result: %s" % str(dict_resp))

    if json:
        print(jsn.dumps(dict_resp, sort_keys=True, indent=4))
        return
    try:
        app.print_details(dict_resp, max_width=max_width)
    except Exception as e:
        sys.exit("failed to print applications:  %s" % str(e))
Example #5
0
def del_instance(name):
    """delete the docker instances"""
    if name is None:
        click.echo("docker instance name is needed.")
        sys.exit(1)
    kargs = {
        'host': c.cfg['host'],
        "api_version": c.cfg['api_version'],
        "url_path": "/applications"
    }
    app = esapp.App(kargs)
    try:
        dict_resp = app.del_instance_by_name(name.split())
    except Exception as e:
        sys.exit("failed to delete instance:  %s" % str(e))

    click.echo("Success to delete")
Example #6
0
def delete(id):
    """Remove a application"""
    if id is None:
        click.echo("A application ID is needed.")
        sys.exit(1)

    kargs = {
        'host': c.cfg['host'],
        "api_version": c.cfg['api_version'],
        "url_path": "/applications"
    }
    app = esapp.App(kargs)
    try:
        dict_resp = app.delete_app_by_id(id)
    except Exception as e:
        sys.exit("failed to delete instance:  %s" % str(e))

    click.echo("Success to delete")
Example #7
0
def instance(json):
    """query and list the docker instances"""

    kargs = {
        'host': c.cfg['host'],
        "api_version": c.cfg['api_version'],
        "url_path": "/applications"
    }
    app = esapp.App(kargs)
    try:
        dict_resp = app.instances()
    except Exception as e:
        sys.exit("failed to query instance:  %s" % str(e))

    if json:
        print(jsn.dumps(dict_resp, sort_keys=True, indent=4))
        return

    app.print_instances(dict_resp)
Example #8
0
def create(name, image_name, vendor_id, commands, cmdargs, pic, description):
    """Create a new Application."""

    kargs = {
        'host': c.cfg['host'],
        "api_version": c.cfg['api_version'],
        "url_path": "/applications"
    }
    app = esapp.App(kargs)

    registry_id = 0
    m_list = app.get_registry()['mirrors']
    for m in m_list:
        if m['name'] == "hub.docker.com":
            registry_id = m['id']

    input_mirror = image_name.split('/')[0]
    for m in m_list:
        if m['name'] == input_mirror:
            registry_id = m['id']

    # Gen image name and version/tag
    nl = image_name.split(':')
    if len(nl) != 2:
        sys.exit("wrong image format, see help")
    _image_name = nl[0]
    _image_version = nl[1]

    click.echo("Image info: %s %s:%s" %
               (str(registry_id), _image_name, _image_version))

    try:
        dict_resp= app.create(name, registry_id, _image_name, _image_version, \
                vendor_id, pic, commands, cmdargs, description)
    except Exception as e:
        sys.exit("failed to create applications:  %s" % str(e))

    if dict_resp == None:
        click.echo("fail to create application")
        sys.exit(1)

    click.echo("Success to create application %s" % name)
Example #9
0
def show(id):
    """query and show specific application (id given) same as "escl app list --id xx" """

    kargs = {
        'host': c.cfg['host'],
        "api_version": c.cfg['api_version'],
        "url_path": "/applications"
    }
    app = esapp.App(kargs)
    try:
        dict_resp = app.show(id)
    except Exception as e:
        sys.exit("Fail applications:  %s" % str(e))

    if dict_resp == None:
        sys.exit("Fail: response format error")
    try:
        print(jsn.dumps(dict_resp, sort_keys=True, indent=4))
    except Exception as e:
        sys.exit("Fail Application:  %s" % str(e))
Example #10
0
File: mix.py Project: NXP/escli
def get_login(yes):
    """get a docker command to login edgescale registry with username 
       and password.
    """
    click.echo("*** The previous docker login token will be expired")
    if not yes and not click.confirm('*** Do you want to continue?'):
        sys.exit(0)

    kargs = {
        'host': c.cfg['host'],
        "api_version": c.cfg['api_version'],
        "url_path": "/applications"
    }
    app = esapp.App(kargs)
    try:
        dict_resp = app.get_registry_login()
    except Exception as e:
        sys.exit("failed: %s" % str(e))

    if 'status' in dict_resp and dict_resp['status'] == 'success':
        click.echo("*** Command to login edgescale registry:\n\t %s" %
                   dict_resp['cmd'])
    else:
        sys.exit("failed to get login command")