Skip to main content

Cisco DNA Center App Hosting SDK

Project description

ciscodnacapphosting

Docker Cloud Build Status Docker Cloud Automated build Docker Pulls Docker Image Version (latest by date)
PyPI - Downloads PyPI - Wheel PyPI

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.

Prerequisites

  • Cisco DNA Center
    • Supported release: 2.1.2+
  • Cisco Catalyst 9000 Switches/APs
  • Python
    • Version: 3.8+

Import Docker images to Cisco DNA Center application hosting

If you develop your own container images, then you can use this tool to automatically upload or update those container to any Cisco DNA Center Application Hosting Repository (using the Platform API).

It's possible to use this tool together with your CI/CD by adding these steps

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

Creating containers on your own workstation/development environment?
No worries, just install this tool through pip and upload your container directly to Cisco DNA Center.

This code is also shared on Cisco DevNet Code Exchange - cisco-dnac-app-hosting-import-docker-images

Application Hosting

Application Hosting on Catalyst 9000 series switches

Related Sandbox

IOS XE on Catalyst 9000 16.12 Code

Links to DevNet Learning Labs

Application Hosting on IOS XE Learning Lab

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.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

ciscodnacapphosting-0.1.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file ciscodnacapphosting-0.1.1.tar.gz.

File metadata

  • Download URL: ciscodnacapphosting-0.1.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for ciscodnacapphosting-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d568aecaf01c132da6aa42d5bf27b2cfb17f364b9035449ccf711027241354c3
MD5 e6b89497a74a3ab15b6dc221829812bc
BLAKE2b-256 0980570eb1ce9f477db5efdd9846da1d0c514eebc12a5dcea85f23d28098a890

See more details on using hashes here.

File details

Details for the file ciscodnacapphosting-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ciscodnacapphosting-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for ciscodnacapphosting-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a614d841d65a8f3b86c17b0ac9dfb9f1ee37f843958030e5f8b2692cc4f5846
MD5 e284ee663519d5b7c219defc6142a97b
BLAKE2b-256 8cc5dc65366df7850f59c79c05a7907f69d1b96d7dd59f3836d36db30047f75a

See more details on using hashes here.

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