How to Upload Content to the Satellite Server repository using API?

Solution Verified - Updated

Environment

  • Red Hat Satellite 6.8, 6.9, 6.10
  • API

Issue

  • How to upload packages and add to a repository directly through the HTTP API instead of using hammer cli ?

  • How to use API to upload packages to a custom repository on Satellite 6 server ?

Resolution

  • First we need to create an upload request POSTing an empty json to the /upload_content endpoint:

      ## Command for Satellite 6.8 and 6.9
      $ curl -ku admin:changeme -H 'Content-Type: application/json' -X POST https://satellite.example.com/katello/api/v2/repositories/1/content_uploads
    
      This will generate the following output
      {
        "upload_id": "4929f9b4-a267-4a09-9364-4debcb86dff1",
        "_href": "/pulp/api/v2/content/uploads/4929f9b4-a267-4a09-9364-4debcb86dff1/"
      }
    
    
      ## Command for Satellite 6.10+
      You will need to get checksum and size of the packages to be used
      
      Checksum: 
      $ sha256sum /root/import-export-sat.usersys.redhat.com-foreman-proxy-client-1.0-1.noarch.rpm
      1f21412545e82715c7c795455cf201334dbde950ff31037867f33007b26430c9  /root/import-export-sat.usersys.redhat.com-foreman-proxy-client-1.0-1.noarch.rpm
    
      Size
      $ ls -l /root/import-export-sat.usersys.redhat.com-foreman-proxy-client-1.0-1.noarch.rpm
      -rw-------. 1 root root 12542 Jan 11 13:55 /root/import-export-sat.usersys.redhat.com-foreman-proxy-client-1.0-1.noarch.rpm
    
      Get the upload_id (using size + checksum): 
      $ curl -H 'Content-Type: application/json' -X POST -k -u admin:changeme  -d '{"size": 12542, "checksum": "1f21412545e82715c7c795455cf201334dbde950ff31037867f33007b26430c9"}' https://satellite.example.com/katello/api/repositories/1/content_uploads
    
      This will generate the following output
      {"upload_id":"f0a5882e-b76e-4813-b4ab-f8880fcb9138}
    
  • This will get us the upload_id, which we need to pass into the actual upload request (note the content-type):

        ## Command for Satellite 6.8 and 6.9
        # curl -H "Accept:application/json;version=2" -H "Content-Type:multipart/form-data" -X PUT -u admin:changeme -k --data-urlencode "content@/home/rplevka/foo.rpm"  --data-urlencode offset=0 https://satellite.example.com/katello/api/repositories/1/content_uploads/4929f9b4-a267-4a09-9364-4debcb86dff1
    
        ## Command for Satellite 6.10+
        #  curl -u admin:changeme -H Accept:application/json -H Content-Type:multipart/form-data -X PUT --data-urlencode size=12542 --data-urlencode offset=0 --data-urlencode content@/root/import-export-sat.usersys.redhat.com-foreman-proxy-client-1.0-1.noarch.rpm https://satellite.example.com/katello/api/v2/repositories/1/content_uploads/f0a5882e-b76e-4813-b4ab-f8880fcb9138
    
    

    this will POST the file to the satellite in a single request, this might be done by chunks with multiple requests, increasing the 'offset' option accordingly.

  • Once the package has been added to satellite we need to upload this rpm to a repo by executing import_uploads request:

      # # Command for Sat6.8 and Sat 6.9
      # curl -H "Content-Type:application/json" -X PUT -u admin:changeme -k -d '{"uploads":[{"id": "4929f9b4-a267-4a09-9364-4debcb86dff1"}]}' https://satellite.example.com/katello/api/repositories/1/import_uploads
    
      # # Command for Sat 6.10+
      # curl -H "Content-Type:application/json" -X PUT -u admin:changeme -k -d '{"uploads":[{"id": "f0a5882e-b76e-4813-b4ab-f8880fcb9138", "name": "import-export-sat.usersys.redhat.com-foreman-proxy-client-1.0-1.noarch.rpm", "checksum": "1f21412545e82715c7c795455cf201334dbde950ff31037867f33007b26430c9" }]}' https://satellite.example.com/katello/api/v2/repositories/1/import_uploads
    
  • Delete an upload request:

      # curl -H "Accept:application/json;version=2" -X DELETE -u admin:changeme -k https://satellite.example.com/katello/api/repositories/1/content_uploads/4929f9b4-a267-4a09-9364-4debcb86dff1
    
  • For more information refer Satellite documentation.

For more KB articles/solutions related to Red Hat Satellite 6.x Repository Issues, please refer to the Red Hat Satellite Consolidated Troubleshooting Article for Red Hat Satellite 6.x Repository Issues.

SBR
Product(s)
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.