Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/robertcsapo/ciscodnacapphosting

ciscodnacapphosting Python SDK for Cisco DNA Center Application Hosting API
https://github.com/robertcsapo/ciscodnacapphosting

api catalyst-9k cisco cisco-dna-center containers docker iox python

Last synced: about 2 months ago
JSON representation

ciscodnacapphosting Python SDK for Cisco DNA Center Application Hosting API

Awesome Lists containing this project

README

        

# ciscodnacapphosting
![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/robertcsapo/ciscodnacapphosting)
![Docker Cloud Automated build](https://img.shields.io/docker/cloud/automated/robertcsapo/ciscodnacapphosting)
![Docker Pulls](https://img.shields.io/docker/pulls/robertcsapo/ciscodnacapphosting)
![Docker Image Version (latest by date)](https://img.shields.io/docker/v/robertcsapo/ciscodnacapphosting)
![PyPI - Downloads](https://img.shields.io/pypi/dm/ciscodnacapphosting)
![PyPI - Wheel](https://img.shields.io/pypi/wheel/ciscodnacapphosting)
![PyPI](https://img.shields.io/pypi/v/ciscodnacapphosting)

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](https://developer.cisco.com/codeexchange/github/repo/robertcsapo/cisco-dnac-app-hosting-import-docker-images)

## Application Hosting
[Application Hosting on Catalyst 9000 series switches](https://developer.cisco.com/app-hosting/)

## Related Sandbox
[IOS XE on Catalyst 9000 16.12 Code](https://devnetsandbox.cisco.com/RM/Diagram/Index/98d5a0fb-1b92-4b5b-abf6-a91e0ddba241?diagramType=Topology)

## Links to DevNet Learning Labs
[Application Hosting on IOS XE Learning Lab](https://developer.cisco.com/learning/modules/app-hosting-cat9k)

# Demo
```bash
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'
```
```bash
ciscodnacapphosting docker --download alpine:3.12.0 --save
Download completed (alpine) - saved as alpine-3.12.0.tar
```
```bash
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](https://pip.pypa.io/en/stable/) to install ```ciscodnacapphosting```.

```bash
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```
```bash
export DNAC_CONFIG=ewogICAgImRuYWMiOiB7CiAgICAgICAgImhvc3RuYW1lIjogImRuYWMuZXhhbXBsZS50bGQiLAogICAgICAgICJ1c2VybmFtZSI6ICJzdXBlcmFkbWluIiwKICAgICAgICAicGFzc3dvcmQiOiAic3VwZXJwYXNzd29yZCIsCiAgICAgICAgInNlY3VyZSI6IHRydWUKICAgIH0KfQ==
```

### CLI

```bash
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
```bash
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

```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/](./examples) folder)_

### Docker
```docker
docker run -it --rm --privileged -e DNAC_CONFIG=ewogICAgImRuYWMiOiB7CiAgICAgICAgImhvc3RuYW1lIjogImRuYWMuZXhhbXBsZS50bGQiLAogICAgICAgICJ1c2VybmFtZSI6ICJzdXBlcmFkbWluIiwKICAgICAgICAicGFzc3dvcmQiOiAic3VwZXJwYXNzd29yZCIsCiAgICAgICAgInNlY3VyZSI6IHRydWUKICAgIH0KfQ== robertcsapo/ciscodnacapphosting
```
```bash
/ # ciscodnacapphosting whoami
Config: {"dnac": {"hostname": "dnac.example.tld", "username": "superadmin", "password": "superpassword", "secure": true}}
/ #
```
```bash
/ # 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:**

- [Cisco DNA Center Platform API](https://developer.cisco.com/dnacenter/)
- [Docker](https://www.docker.com/get-started)
- [dockerpy](https://github.com/docker/docker-py/)

## Authors & Maintainers

- Robert Csapo

## 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](./LICENSE).