Getting Started with Packaging API

Prerequisites

  • Python 3 (version 3.6 and above)
  • quali_utils.3.3.0.tar.gz

    Note: quali_utils.3.3.0 is supported by CloudShell 2022.1 and above. For previous versions, see earlier versions of CloudShell Help.

Installation

  1. Make sure you have a compatible Python version installed on your machine.
  2. To download the Python Package Editor that applies to your installed CloudShell version, visit the Python Package Editor Download Page.
  3. Do one of the following:

Code Sample

The following code sample provides an example of how to create new blueprints using the API. This example demonstrates how to perform the following flow:

This example uses the “requests” python module.

from quali_utils.quali_packaging import PackageEditor import requests

#Create a new package in the local file system

p = PackageEditor()

p.create("c:\\myfolder\\mypack.zip")




#Load the package and prepare for edit

p.load("c:\\myfolder\\mypack.zip")

#Edit the package: f.e add new family

p.add_family("Ball", "", ["Game", "3D Shape", "MoreStuff"], False, False, False, False, True)


#Import the package into CloudShell

# 1 – authenticate

r = requests.put('http://localhost:9000/Api/Auth/Login', {"username": "admin", "password": "admin", "domain": "Global"})

authcode = "Basic " + response._content[1:-1]


#2 – Open the package before import

fileobj = open("c:\\p.zip", 'rb')

#3 – Send to CloudShell by calling Import Package REST API

r = requests.post('http://localhost:9000/API/Package/ImportPackage',

                 headers={"Authorization": authcode},

                 files={"file": fileobj})
print r._content

print r.ok