Skip to content

Instantly share code, notes, and snippets.

@lucassrg
Created March 13, 2020 05:17
Show Gist options
  • Save lucassrg/df220ded079d3b3bd22b072ccf075ed2 to your computer and use it in GitHub Desktop.
Save lucassrg/df220ded079d3b3bd22b072ccf075ed2 to your computer and use it in GitHub Desktop.
subscribe to marketplace listing
# coding: utf-8
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
# This script subscribes to the default package of a Marketplace listing by accepting all terms and conditions and list all subscriptions
#
#
#
#
import oci
compartment_id = "ocid1.compartment."
listing_id = "ocid number"
config = oci.config.from_file('./oci_config')
mpc = oci.marketplace.MarketplaceClient(config, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY)
#use default package version or specify one
listing = mpc.get_listing(listing_id).data
package_version = listing.default_package_version
# listing typically have more than one agreement
agreementSummaryList = mpc.list_agreements(listing_id, package_version).data
agreementList = list()
#retrieve all agreements
for agreementSummary in agreementSummaryList:
agreement_id = agreementSummary.id
agreement = mpc.get_agreement(listing_id, package_version, agreement_id).data
agreementList.append(agreement)
#print(agreement)
#accept agreement
for agreement in agreementList:
acceptedAgreementDetails = oci.marketplace.models.CreateAcceptedAgreementDetails()
acceptedAgreementDetails.agreement_id = agreement.id
acceptedAgreementDetails.compartment_id = compartment_id
acceptedAgreementDetails.listing_id = listing_id
acceptedAgreementDetails.package_version = package_version
acceptedAgreementDetails.signature = agreement.signature
acceptedAgreementDetails.display_name = "my-agreement-"+agreement.id
acceptedAgreement = mpc.create_accepted_agreement(acceptedAgreementDetails).data
print(acceptedAgreement)
print("Accepted agreements")
print(mpc.list_accepted_agreements(compartment_id, listing_id = listing_id).data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment