Skip to main content

Cisco DNA Center App Hosting SDK

Project description

cisco-dnac-app-hosting-import-docker-images

Disclaimer This solution leverages currently unpublished Cisco DNA Center APIs (as of DATE) Do not use in production

ciscodnacapphosting is a Python SDK for Cisco DNA Center Application Hosting API.
It uses local docker environment to pull and save docker images.

Demo

ciscodnacapphosting app --image busybox
Get App (busybox)
data:
- _links:
    configuration:
      href: /api/v1/appmgr/apps/71257f4a-1f68-43a5-85f0-3347137107bb/1.32/config
    icon:
      href: null
    images:
      href: /api/v1/appmgr/apps/71257f4a-1f68-43a5-85f0-3347137107bb/1.32/images
    packages:
      href: /api/v1/appmgr/apps/71257f4a-1f68-43a5-85f0-3347137107bb/1.32/packages
    self:
      href: /api/v1/appmgr/apps/71257f4a-1f68-43a5-85f0-3347137107bb/1.32
  appId: 71257f4a-1f68-43a5-85f0-3347137107bb
  appType: docker
  categories:
  - IOT
  classification: APP
  cpuUsage: 0
  description:
    contentType: text
  descriptor:
    app:
      cpuarch: x86_64
      env:
        PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      resources:
        network:
        - interface-name: eth0
          ports: {}
        profile: c1.large
      startup:
        rootfs: fogd_upload_8699102144278681062.tar
        target:
        - sh
      type: docker
    descriptor-schema-version: '2.2'
    info:
      name: busybox
      version: '1.32'
  icon:
    caption: icon
    href: null
  images: []
  lastUpdatedDate: 1604930943165
  localAppId: 71257f4a-1f68-43a5-85f0-3347137107bb
  memoryUsage: 0
  name: busybox
  packages:
  - href: /api/v1/appmgr/apps/71257f4a-1f68-43a5-85f0-3347137107bb/1.32/packages/b55be543-b969-415b-b47d-da95df834a5f
  profileNeeded: c1.large
  properties: []
  published: true
  releaseNotes:
    contentType: text
  services: []
  signed: false
  version: '1.32'
ciscodnacapphosting docker --download alpine:3.12.0 --save
Download completed (alpine) - saved as alpine-3.12.0.tar
ciscodnacapphosting upload --file alpine-3.12.0.tar --categories IOT
Upload App (alpine-3.12.0.tar) - IOT
New AppId (1a12b3d9-22d5-40ee-8aff-e2ccfb79c59f) alpine:3.12.0 - IOT

Installation

Use the package manager pip to install ciscodnacapphosting.

pip install ciscodnacapphosting

Usage

Configuration can be stored in config.json in JSON format.

{
    "dnac": {
        "hostname": "dnac.example.tld",
        "username": "superadmin",
        "password": "superpassword",
        "secure": true
    }
}

(secure parameter is for HTTPS verification)

The configuration can be encoded as base64 string. ewogICAgImRuYWMiOiB7CiAgICAgICAgImhvc3RuYW1lIjogImRuYWMuZXhhbXBsZS50bGQiLAogICAgICAgICJ1c2VybmFtZSI6ICJzdXBlcmFkbWluIiwKICAgICAgICAicGFzc3dvcmQiOiAic3VwZXJwYXNzd29yZCIsCiAgICAgICAgInNlY3VyZSI6IHRydWUKICAgIH0KfQ==

If using base64 encoded, then it's possible to set Environment DNAC_CONFIG

export DNAC_CONFIG=ewogICAgImRuYWMiOiB7CiAgICAgICAgImhvc3RuYW1lIjogImRuYWMuZXhhbXBsZS50bGQiLAogICAgICAgICJ1c2VybmFtZSI6ICJzdXBlcmFkbWluIiwKICAgICAgICAicGFzc3dvcmQiOiAic3VwZXJwYXNzd29yZCIsCiAgICAgICAgInNlY3VyZSI6IHRydWUKICAgIH0KfQ==

CLI

ciscodnacapphosting config --hostname dnac.example.tld --username superadmin --password superpassword --secure --encode

ciscodnacapphosting app
ciscodnacapphosting app--image busybox

ciscodnacapphosting docker
ciscodnacapphosting docker --download busybox:1.31 --save

ciscodnacapphosting upload --file busybox-1.31.tar --categories IOT

ciscodnacapphosting upgrade --id 71257f4a-1f68-43a5-85f0-3347137107bb --tag 1.31 --file busybox-1.32.tar --categories IOT

ciscodnacapphosting update --id 71257f4a-1f68-43a5-85f0-3347137107bb --categories Security

ciscodnacapphosting delete --id 71257f4a-1f68-43a5-85f0-3347137107bb --tag 1.31

Help

ciscodnacapphosting --help
Usage: ciscodnacapphosting [OPTIONS] COMMAND1 [ARGS]... [COMMAND2
                           [ARGS]...]...

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  app
  config
  delete
  docker
  update
  upgrade
  upload
  whoami

Include in Python

import ciscodnacapphosting

dnac_app = ciscodnacapphosting.Api()
download = dnac_app.docker.download(image="busybox", tag="1.31")
save = dnac_app.docker.save(image=download["image"], tag=download["tag"])
upload = dnac_app.upload(tar=save["filename"], categories="IOT")
upgrade = dnac_app.upgrade(
        appId=appId, tag=tag, tar="busybox-1.32.tar", categories="IOT"
    )
update = dnac_app.update(
        appId="46e54562-83c9-4183-8632-c597c8cc5a2b", categories="IOT"
    )
delete = dnac_app.delete(appId=appId, tag=tag)

(More examples in examples/ folder)

Docker

docker run -it --rm --privileged -e DNAC_CONFIG=ewogICAgImRuYWMiOiB7CiAgICAgICAgImhvc3RuYW1lIjogImRuYWMuZXhhbXBsZS50bGQiLAogICAgICAgICJ1c2VybmFtZSI6ICJzdXBlcmFkbWluIiwKICAgICAgICAicGFzc3dvcmQiOiAic3VwZXJwYXNzd29yZCIsCiAgICAgICAgInNlY3VyZSI6IHRydWUKICAgIH0KfQ== robertcsapo/ciscodnacapphosting
/ # ciscodnacapphosting whoami
Config: {"dnac": {"hostname": "dnac.example.tld", "username": "superadmin", "password": "superpassword", "secure": true}}
/ # 
/ # ciscodnacapphosting app --image alpine
Get App (alpine)
data:
- _links:
    configuration:
      href: /api/v1/appmgr/apps/1a12b3d9-22d5-40ee-8aff-e2ccfb79c59f/3.12.0/config
    icon:
      href: null
    images:
      href: /api/v1/appmgr/apps/1a12b3d9-22d5-40ee-8aff-e2ccfb79c59f/3.12.0/images
    packages:
      href: /api/v1/appmgr/apps/1a12b3d9-22d5-40ee-8aff-e2ccfb79c59f/3.12.0/packages
    self:
      href: /api/v1/appmgr/apps/1a12b3d9-22d5-40ee-8aff-e2ccfb79c59f/3.12.0
  appId: 1a12b3d9-22d5-40ee-8aff-e2ccfb79c59f
  appType: docker
  categories:
  - IOT
  classification: APP
  cpuUsage: 0
  creationDate: 1604950418368
  description:
    contentType: text
  descriptor:
    app:
      cpuarch: x86_64
      env:
        PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      resources:
        network:
        - interface-name: eth0
          ports: {}
        profile: c1.large
      startup:
        rootfs: fogd_upload_7626901429300115262.tar
        target:
        - /bin/sh
      type: docker
    descriptor-schema-version: '2.2'
    info:
      name: alpine
      version: 3.12.0
  icon:
    caption: icon
    href: null
  images: []
  localAppId: 1a12b3d9-22d5-40ee-8aff-e2ccfb79c59f
  memoryUsage: 0
  name: alpine
  packages:
  - href: /api/v1/appmgr/apps/1a12b3d9-22d5-40ee-8aff-e2ccfb79c59f/3.12.0/packages/10d8de54-9c21-4f65-bda1-540ef5e4e1ac
  profileNeeded: c1.large
  properties: []
  published: true
  releaseNotes:
    contentType: text
  services: []
  signed: false
  version: 3.12.0

Technologies & Frameworks Used

Cisco Products & Services:

Authors & Maintainers

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed to you under the terms of the Cisco Sample Code License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ciscodnacapphosting-0.1.tar.gz (10.8 kB view hashes)

Uploaded Source

Built Distribution

ciscodnacapphosting-0.1-py3-none-any.whl (12.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page