// This is an automatically generated code sample.
// To make this code sample work in your Oracle Cloud tenancy,
// please replace the values for any parameters whose current values do not fit
// your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
// boolean, number, and enum parameters with values not fitting your use case).
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Oci.SelfService;
using Oci.Common;
using Oci.Common.Auth;
namespace Oci.Sdk.DotNet.Example.Self
{
public class CreateSubscriptionExample
{
public static async Task Main()
{
// Create a request and dependent object(s).
var createSubscriptionDetails = new Oci.SelfService.Models.CreateSubscriptionDetails
{
DisplayName = "EXAMPLE-displayName-Value",
CompartmentId = "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
TenantId = "ocid1.test.oc1..<unique_ID>EXAMPLE-tenantId-Value",
SubscriptionDetails = new Oci.SelfService.Models.SubscriptionDetails
{
PricingPlan = new Oci.SelfService.Models.PricingPlan
{
PlanType = Oci.SelfService.Models.PricingPlan.PlanTypeEnum.Fixed,
PlanName = "EXAMPLE-planName-Value",
PlanDescription = "EXAMPLE-planDescription-Value",
BillingFrequency = Oci.SelfService.Models.PricingPlan.BillingFrequencyEnum.Yearly,
PlanDuration = Oci.SelfService.Models.PricingPlan.PlanDurationEnum.Annual,
Rates = new List<Oci.SelfService.Models.PricingRate>
{
new Oci.SelfService.Models.PricingRate
{
Currency = "5kt",
Rate = (float)2945.8762
}
}
},
PartnerRegistrationUrl = "EXAMPLE-partnerRegistrationUrl-Value",
Currency = "Ex2",
Amount = (float)6488.0864,
BillingDetails = new Oci.SelfService.Models.BillingDetails
{
Sku = "EXAMPLE-sku-Value",
MetricType = Oci.SelfService.Models.MetricType.InstanceHours,
RateAllocation = (float)0.9194852,
HasGovSku = true,
Meters = new List<Oci.SelfService.Models.Meter>
{
new Oci.SelfService.Models.Meter
{
Name = "EXAMPLE-name-Value",
RateAllocation = (float)0.99156684,
ExtendedMetadata = new List<Oci.SelfService.Models.ExtendedMetadata>
{
new Oci.SelfService.Models.ExtendedMetadata
{
Key = "EXAMPLE-key-Value",
Value = "EXAMPLE-value-Value"
}
}
}
}
},
IsAutoRenew = false
},
SellerId = "ocid1.test.oc1..<unique_ID>EXAMPLE-sellerId-Value",
SourceType = Oci.SelfService.Models.SourceType.OciNative,
ProductId = "ocid1.test.oc1..<unique_ID>EXAMPLE-productId-Value",
AdditionalDetails = new List<Oci.SelfService.Models.ExtendedMetadata>
{
new Oci.SelfService.Models.ExtendedMetadata
{
Key = "EXAMPLE-key-Value",
Value = "EXAMPLE-value-Value"
}
},
Realm = "EXAMPLE-realm-Value",
Region = "EXAMPLE-region-Value",
FreeformTags = new Dictionary<string, string>()
{
{
"EXAMPLE_KEY_rwBNY",
"EXAMPLE_VALUE_zofMTUk3GUgJv4cXOGZ9"
}
},
DefinedTags = new Dictionary<string, Dictionary<string, Object>>()
{
{
"EXAMPLE_KEY_iHAqf",
new Dictionary<string, Object>()
{
{
"EXAMPLE_KEY_NkCFw",
"EXAMPLE--Value"
}
}
}
}
};
var createSubscriptionRequest = new Oci.SelfService.Requests.CreateSubscriptionRequest
{
CreateSubscriptionDetails = createSubscriptionDetails,
OpcRetryToken = "EXAMPLE-opcRetryToken-Value",
OpcRequestId = "J81E6G7IWNFDCYZ9L1PM<unique_ID>"
};
// Create a default authentication provider that uses the DEFAULT
// profile in the configuration file.
// Refer to <see href="https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File>the public documentation</see> on how to prepare a configuration file.
var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
try
{
// Create a service client and send the request.
using (var client = new SubscriptionClient(provider, new ClientConfiguration()))
{
var response = await client.CreateSubscription(createSubscriptionRequest);
// Retrieve value from the response.
var id = response.Subscription.Id;
}
}
catch (Exception e)
{
Console.WriteLine($"CreateSubscription Failed with {e.Message}");
throw e;
}
}
}
}