Super Contributor.. Andrew-Ruller Super Contributor..
Super Contributor..
1885 views

Load content packs via CLI/API/REST

Jump to solution

Hi all, 

I'm currently looking for documentation that would allow me to programically deploy a content pack via a Remote Powershell, API or authenticated RESTful interface to OO 10.51

I have found the OO Shell Wizard but this has a gui that appears to replay commands on your behalf.

If anyone could point me in the right direction of some method/doco it would be appreciated.

Thanks, 

Andrew

Labels (1)
0 Likes
1 Solution

Accepted Solutions
Super Contributor.. Andrew-Ruller Super Contributor..
Super Contributor..

Re: Load content packs via CLI/API/REST

Jump to solution

Well I didnt have any luck with the deployment request process so went with a simple PUT upload for my deployment script.. 

 

curl -H "Content-Type: application/x-compressed-tar" -k -X PUT -T "/path/to/contentpack_file.jar"  --user "oo_yser:oo_passwd" https://oo_server:8443/oo/rest/v2/content-packs/contentpack_name_without_dot_jar
15 Replies
guyhanael Absent Member.
Absent Member.

Re: Load content packs via CLI/API/REST

Jump to solution

You can check the "How can I deploy content packs with progress" section the API guide.

0 Likes
lrevnic Absent Member.
Absent Member.

Re: Load content packs via CLI/API/REST

Jump to solution

Hi,

We would like to understand your use cases. For eg are you also creating the CP from CLI?

To deploy a CP from CLI you can also use OO Shell (OOSH) CLI tool that is available with HPE OO.

HTH,

Lucian

0 Likes
Super Contributor.. Andrew-Ruller Super Contributor..
Super Contributor..

Re: Load content packs via CLI/API/REST

Jump to solution

Hi Guy, 

I am working throught he following documentation now in regards to creating a deployment or deploying a content pack via OO REST API.

https://lnast01pcache.saas.hpe.com/asset/resources/pd/oo/gcq1459954671/OO10.51_API_Guide.pdf 

This guide is useful however it doesnt provide any details on the post REQUESTS that need to be made, it just lists the responses. 

this makes it difficult to understand what the API expects in regards to data to facilitate an upload.

I'm currently trying to find information on how to format my request in JSOn. This appears to be consistent for a lot of the calls in the above doco.

Eg: Deploy Content Packs
Request: PUT /content-packs/{cpFileName}

Say I want to upload content pack "cp-xyz.jar" 

Sure I can PUT https://<oocentral>:8443/oo/rest/v2/content-packs/cp-xyz

but how do i specify the source file to PUT? The API guide lacks documentation on what to specify.

Super Contributor.. Andrew-Ruller Super Contributor..
Super Contributor..

Re: Load content packs via CLI/API/REST

Jump to solution

Hi Lucian, 

My use case is I have pre-built Content packs available on a file share. 

I wish to upload these to OO Central via REST, more specifically, from a centos host via CURL or some other utility and ensure the success via a response or return code.

Managing dependancies are not such a big deal at this stage.

I also understand the CSRF-TOKEN requirements in order to PUT/POST to OO.

Thanks, 

Andrew

 

0 Likes
Super Contributor.. Andrew-Ruller Super Contributor..
Super Contributor..

Re: Load content packs via CLI/API/REST

Jump to solution

Screenshot from 2016-06-14 16_20_49.png

 

As you can see from the above screenshot, there are no details on how to define the body of your request to go along with the PUT request. 

Any pointers are appreciated.

Thanks.

reisen Absent Member.
Absent Member.

Re: Load content packs via CLI/API/REST

Jump to solution

Hi,

The body is not JSON, but rather the CP file itself.

Exactly how the file should be formatted, depends on which deployment API you use:

  • In the simpler API, which you referenced, the file should be transfered as a raw stream of bytes. This can be done programmatically.

  • There is also the more advanced "deplyoment with progress" API. In that API, you first create a new deployment process, then add one or more CP files to it, then start the deployment, and finally query it to check its progress.

    In this API, CP files should be added to the body according to the "multipart/form-data" standard (RFC 2388), which is the standard used for uploading files in webpages. This can be done programmatically or through a REST client that supports file upload.


HTH,
Rotem

AndreiTruta Outstanding Contributor.
Outstanding Contributor.

Re: Load content packs via CLI/API/REST

Jump to solution

As an example to what Rotem mentioned

In the Rest Client with upload support your PUT call could look like this

 

PUT /content-packs/{cpFileName&#125;PUT /content-packs/{cpFileName}Hope it helps,

Andrei

 

Andrei Vasile Truta
Absent Member.. Peter_Sutter Absent Member..
Absent Member..

Re: Load content packs via CLI/API/REST

Jump to solution

Yea the documentation wasn't that helpful with content pack deployment. I did get it working with python and requests. Something like this:

import requests

url='https://<OO server>:8443/oo/rest/v2/content-packs/<ContentPackName>'
myheaders={"Content-Type": "application/json"}
files = open('c:\\Content Packs\\<ContentPackName>.jar', 'rb')
r= requests.put(url,data=files,verify=False,auth=('admin','password'),headers=myheaders)

 edit: you don't need to import json

Super Contributor.. Andrew-Ruller Super Contributor..
Super Contributor..

Re: Load content packs via CLI/API/REST

Jump to solution

Rotem, Andrei and Peter, 

Thank you all for highlighting this process to me. I've done some work with API's and restful interfaces but not a great deal. This helps me considerably and will attempt to code this part of my script today. I'm using Postman to help interact with the REST interface and it wasn't immediately obvious how to add a file as part of a put command. Knowing now how it operates I'll look for this functionality specifically.

Thanks again.

Andrew

0 Likes
Super Contributor.. Andrew-Ruller Super Contributor..
Super Contributor..

Re: Load content packs via CLI/API/REST

Jump to solution

Hi Rotem, 

I was able to perform a simple PUT with binary data to upload a content pack and this worked as expected.

Now I'm attempting to use the Deployment process and still am a big vague about the explicit parameters I define and provide as part of a Deployment Process file.

As per the API guide:  "The request should be formatted according to the "multipart/form-data" standard for uploading files to a web server (RFC 2388). Note: The request body should be the contents of the content pack files to be deployed."

When defining the multipart/form-data, its usually a key value pair. And while I'm able to define a value as a type of file and direct it to the content pack to upload, I'm not having any success with providing the correct key name. I've used name, file, content-pack which all respond with a 500 error. The documentation also doesn't define what form-data key name to use to upload this file.

Are youa able to assist with this detail?

Thanks, 

Andrew

0 Likes
reisen Absent Member.
Absent Member.

Re: Load content packs via CLI/API/REST

Jump to solution

Hi Andrew,

I believe there are two relevant names for each file - the name of the HTML form input, which is irrelevant, and the filename, which is important, and should match the actual filename.

If you still can't get it to work, try checking the Central logs under central/var/logs. There will probably be an error in wrapper.log or server.log (maybe general.log).

Unfortunately I can't help with the code itself, since this is highly dependent on the language you use.

HTH,
Rotem

Super Contributor.. Andrew-Ruller Super Contributor..
Super Contributor..

Re: Load content packs via CLI/API/REST

Jump to solution

Thanks Rotem, 

I'll have another poke around and see what I can find in the logs. Appreciate the pointers!

Cheers, 

Andrew

0 Likes
Super Contributor.. Andrew-Ruller Super Contributor..
Super Contributor..

Re: Load content packs via CLI/API/REST

Jump to solution

Well I didnt have any luck with the deployment request process so went with a simple PUT upload for my deployment script.. 

 

curl -H "Content-Type: application/x-compressed-tar" -k -X PUT -T "/path/to/contentpack_file.jar"  --user "oo_yser:oo_passwd" https://oo_server:8443/oo/rest/v2/content-packs/contentpack_name_without_dot_jar
Micro Focus Contributor
Micro Focus Contributor

Re: Load content packs via CLI/API/REST

Jump to solution

I know this is older post,

considering there was never given example of the REST API, here it is: 

In my case this was done with "Advanced REST client" 

As always of course you need to do some GET call in order to retrieve the CSRF token, it will be in response headers of the call. Once you have that, you can move to the PUT method, with following request URL:

https://<hostname or IP or FQDN:port>/oo/rest/v2/content-packs/<name of content pack without extension>

Headers you going to need :

headers.JPG

In the body you need to choose the file :

body.JPG

 

Make sure the content pack you are deploying via API already has all the dependencies deployed in the central.  

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.