// 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.CoreService;
using Oci.Common;
using Oci.Common.Auth;

namespace Oci.Sdk.DotNet.Example.Core
{
    public class LaunchInstanceExample
    {
        public static async Task Main()
        {
            // Create a request and dependent object(s).
			var launchInstanceDetails = new Oci.CoreService.Models.LaunchInstanceDetails
			{
				AvailabilityDomain = "EXAMPLE-availabilityDomain-Value",
				CapacityReservationId = "ocid1.test.oc1..<unique_ID>EXAMPLE-capacityReservationId-Value",
				CompartmentId = "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
				CreateVnicDetails = new Oci.CoreService.Models.CreateVnicDetails
				{
					AssignIpv6Ip = true,
					AssignPublicIp = true,
					AssignPrivateDnsRecord = false,
					DefinedTags = new Dictionary<string, Dictionary<string, Object>>()
					{
						{
							"EXAMPLE_KEY_d7qSe", 
							new Dictionary<string, Object>()
							{
								{
									"EXAMPLE_KEY_UwHFL", 
									"EXAMPLE--Value"
								}
							}
						}
					},
					DisplayName = "EXAMPLE-displayName-Value",
					FreeformTags = new Dictionary<string, string>()
					{
						{
							"EXAMPLE_KEY_pltCT", 
							"EXAMPLE_VALUE_8WY49bidM42zHrAznDAx"
						}
					},
					HostnameLabel = "EXAMPLE-hostnameLabel-Value",
					Ipv6AddressIpv6SubnetCidrPairDetails = new List<Oci.CoreService.Models.Ipv6AddressIpv6SubnetCidrPairDetails>
					{
						new Oci.CoreService.Models.Ipv6AddressIpv6SubnetCidrPairDetails
						{
							Ipv6SubnetCidr = "EXAMPLE-ipv6SubnetCidr-Value",
							Ipv6Address = "EXAMPLE-ipv6Address-Value"
						}
					},
					NsgIds = new List<string>
					{
						"EXAMPLE--Value"
					},
					PrivateIp = "EXAMPLE-privateIp-Value",
					SkipSourceDestCheck = true,
					SubnetId = "ocid1.test.oc1..<unique_ID>EXAMPLE-subnetId-Value",
					VlanId = "ocid1.test.oc1..<unique_ID>EXAMPLE-vlanId-Value"
				},
				DedicatedVmHostId = "ocid1.test.oc1..<unique_ID>EXAMPLE-dedicatedVmHostId-Value",
				DefinedTags = new Dictionary<string, Dictionary<string, Object>>()
				{
					{
						"EXAMPLE_KEY_XtJro", 
						new Dictionary<string, Object>()
						{
							{
								"EXAMPLE_KEY_jibuR", 
								"EXAMPLE--Value"
							}
						}
					}
				},
				DisplayName = "EXAMPLE-displayName-Value",
				ExtendedMetadata = new Dictionary<string, Object>()
				{
					{
						"EXAMPLE_KEY_u88Nz", 
						"EXAMPLE--Value"
					}
				},
				FaultDomain = "EXAMPLE-faultDomain-Value",
				ClusterPlacementGroupId = "ocid1.test.oc1..<unique_ID>EXAMPLE-clusterPlacementGroupId-Value",
				FreeformTags = new Dictionary<string, string>()
				{
					{
						"EXAMPLE_KEY_39FwN", 
						"EXAMPLE_VALUE_s5Ght81OAB1JjaPHIn83"
					}
				},
				ComputeClusterId = "ocid1.test.oc1..<unique_ID>EXAMPLE-computeClusterId-Value",
				HostnameLabel = "EXAMPLE-hostnameLabel-Value",
				ImageId = "ocid1.test.oc1..<unique_ID>EXAMPLE-imageId-Value",
				IpxeScript = "EXAMPLE-ipxeScript-Value",
				LaunchOptions = new Oci.CoreService.Models.LaunchOptions
				{
					BootVolumeType = Oci.CoreService.Models.LaunchOptions.BootVolumeTypeEnum.Iscsi,
					Firmware = Oci.CoreService.Models.LaunchOptions.FirmwareEnum.Uefi64,
					NetworkType = Oci.CoreService.Models.LaunchOptions.NetworkTypeEnum.Paravirtualized,
					RemoteDataVolumeType = Oci.CoreService.Models.LaunchOptions.RemoteDataVolumeTypeEnum.Ide,
					IsPvEncryptionInTransitEnabled = true,
					IsConsistentVolumeNamingEnabled = true
				},
				InstanceOptions = new Oci.CoreService.Models.InstanceOptions
				{
					AreLegacyImdsEndpointsDisabled = false
				},
				AvailabilityConfig = new Oci.CoreService.Models.LaunchInstanceAvailabilityConfigDetails
				{
					IsLiveMigrationPreferred = false,
					RecoveryAction = Oci.CoreService.Models.LaunchInstanceAvailabilityConfigDetails.RecoveryActionEnum.StopInstance
				},
				PreemptibleInstanceConfig = new Oci.CoreService.Models.PreemptibleInstanceConfigDetails
				{
					PreemptionAction = new Oci.CoreService.Models.TerminatePreemptionAction
					{
						PreserveBootVolume = false
					}
				},
				Metadata = new Dictionary<string, string>()
				{
					{
						"EXAMPLE_KEY_JhWbU", 
						"EXAMPLE_VALUE_q2CgMvKzKZHef6ax54Bx"
					}
				},
				AgentConfig = new Oci.CoreService.Models.LaunchInstanceAgentConfigDetails
				{
					IsMonitoringDisabled = true,
					IsManagementDisabled = true,
					AreAllPluginsDisabled = false,
					PluginsConfig = new List<Oci.CoreService.Models.InstanceAgentPluginConfigDetails>
					{
						new Oci.CoreService.Models.InstanceAgentPluginConfigDetails
						{
							Name = "EXAMPLE-name-Value",
							DesiredState = Oci.CoreService.Models.InstanceAgentPluginConfigDetails.DesiredStateEnum.Disabled
						}
					}
				},
				Shape = "EXAMPLE-shape-Value",
				ShapeConfig = new Oci.CoreService.Models.LaunchInstanceShapeConfigDetails
				{
					Ocpus = (float)1770.9791,
					Vcpus = 250,
					MemoryInGBs = (float)3181.5088,
					BaselineOcpuUtilization = Oci.CoreService.Models.LaunchInstanceShapeConfigDetails.BaselineOcpuUtilizationEnum.Baseline11,
					Nvmes = 2
				},
				SourceDetails = new Oci.CoreService.Models.InstanceSourceViaBootVolumeDetails
				{
					BootVolumeId = "ocid1.test.oc1..<unique_ID>EXAMPLE-bootVolumeId-Value"
				},
				SubnetId = "ocid1.test.oc1..<unique_ID>EXAMPLE-subnetId-Value",
				LaunchVolumeAttachments = new List<Oci.CoreService.Models.LaunchAttachVolumeDetails>
				{
					new Oci.CoreService.Models.LaunchAttachIScsiVolumeDetails
					{
						UseChap = true,
						EncryptionInTransitType = Oci.CoreService.Models.EncryptionInTransitType.BmEncryptionInTransit,
						IsAgentAutoIscsiLoginEnabled = false,
						Device = "EXAMPLE-device-Value",
						DisplayName = "EXAMPLE-displayName-Value",
						IsReadOnly = false,
						IsShareable = false,
						VolumeId = "ocid1.test.oc1..<unique_ID>EXAMPLE-volumeId-Value",
						LaunchCreateVolumeDetails = new Oci.CoreService.Models.LaunchCreateVolumeFromAttributes
						{
							CompartmentId = "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
							DisplayName = "EXAMPLE-displayName-Value",
							KmsKeyId = "ocid1.test.oc1..<unique_ID>EXAMPLE-kmsKeyId-Value",
							VpusPerGB = 725,
							SizeInGBs = 120
						}
					}
				},
				IsPvEncryptionInTransitEnabled = true,
				PlatformConfig = new Oci.CoreService.Models.AmdMilanBmLaunchInstancePlatformConfig
				{
					NumaNodesPerSocket = Oci.CoreService.Models.AmdMilanBmLaunchInstancePlatformConfig.NumaNodesPerSocketEnum.Nps4,
					IsSymmetricMultiThreadingEnabled = false,
					IsAccessControlServiceEnabled = true,
					AreVirtualInstructionsEnabled = true,
					IsInputOutputMemoryManagementUnitEnabled = true,
					PercentageOfCoresEnabled = 93,
					ConfigMap = new Dictionary<string, string>()
					{
						{
							"EXAMPLE_KEY_KV0BF", 
							"EXAMPLE_VALUE_A8Fl5rUazAEpzxHGusgV"
						}
					},
					IsSecureBootEnabled = true,
					IsTrustedPlatformModuleEnabled = false,
					IsMeasuredBootEnabled = false,
					IsMemoryEncryptionEnabled = true
				},
				InstanceConfigurationId = "ocid1.test.oc1..<unique_ID>EXAMPLE-instanceConfigurationId-Value"
			};
			var launchInstanceRequest = new Oci.CoreService.Requests.LaunchInstanceRequest
			{
				LaunchInstanceDetails = launchInstanceDetails,
				OpcRetryToken = "EXAMPLE-opcRetryToken-Value"
			};

            // 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 ComputeClient(provider, new ClientConfiguration()))
				{
					var response = await client.LaunchInstance(launchInstanceRequest);
					// Retrieve value from the response.
					var id = response.Instance.Id;
				}
            }
            catch (Exception e)
            {
                Console.WriteLine($"LaunchInstance Failed with {e.Message}");
                throw e;
            }
        }

    }
}