# 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).

require 'oci'

# Create a default config using DEFAULT profile in default location
# Refer to https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File for more info
config = OCI::ConfigFileLoader.load_config

# Initialize service client with default config file
core_client = OCI::Core::ComputeClient.new(config: config)

# Send the request to service, some parameters are not required, see API doc for more info
launch_instance_response =
  core_client.launch_instance(
    OCI::Core::Models::LaunchInstanceDetails.new(
      availability_domain: 'EXAMPLE-availabilityDomain-Value',
      compartment_id: 'ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value',
      capacity_reservation_id:
        'ocid1.test.oc1..<unique_ID>EXAMPLE-capacityReservationId-Value',
      create_vnic_details:
        OCI::Core::Models::CreateVnicDetails.new(
          assign_ipv6_ip: false,
          assign_public_ip: false,
          assign_private_dns_record: true,
          defined_tags: {
            'EXAMPLE_KEY_B66m7' => { 'EXAMPLE_KEY_o96bb' => 'EXAMPLE--Value' }
          },
          display_name: 'EXAMPLE-displayName-Value',
          freeform_tags: {
            'EXAMPLE_KEY_pwUqQ' => 'EXAMPLE_VALUE_gDv3uovFr0QaHpsEUrc9'
          },
          security_attributes: {
            'EXAMPLE_KEY_i2nox' => { 'EXAMPLE_KEY_uDy8o' => 'EXAMPLE--Value' }
          },
          hostname_label: 'EXAMPLE-hostnameLabel-Value',
          ipv6_address_ipv6_subnet_cidr_pair_details: [
            OCI::Core::Models::Ipv6AddressIpv6SubnetCidrPairDetails.new(
              ipv6_subnet_cidr: 'EXAMPLE-ipv6SubnetCidr-Value',
              ipv6_address: 'EXAMPLE-ipv6Address-Value'
            )
          ],
          nsg_ids: %w[EXAMPLE--Value],
          private_ip: 'EXAMPLE-privateIp-Value',
          skip_source_dest_check: true,
          subnet_id: 'ocid1.test.oc1..<unique_ID>EXAMPLE-subnetId-Value',
          vlan_id: 'ocid1.test.oc1..<unique_ID>EXAMPLE-vlanId-Value'
        ),
      dedicated_vm_host_id:
        'ocid1.test.oc1..<unique_ID>EXAMPLE-dedicatedVmHostId-Value',
      defined_tags: {
        'EXAMPLE_KEY_QtEBb' => { 'EXAMPLE_KEY_spFDN' => 'EXAMPLE--Value' }
      },
      security_attributes: {
        'EXAMPLE_KEY_GcYq7' => { 'EXAMPLE_KEY_4DYKf' => 'EXAMPLE--Value' }
      },
      display_name: 'EXAMPLE-displayName-Value',
      extended_metadata: { 'EXAMPLE_KEY_lKlyl' => 'EXAMPLE--Value' },
      fault_domain: 'EXAMPLE-faultDomain-Value',
      cluster_placement_group_id:
        'ocid1.test.oc1..<unique_ID>EXAMPLE-clusterPlacementGroupId-Value',
      freeform_tags: {
        'EXAMPLE_KEY_6hbEY' => 'EXAMPLE_VALUE_XDesjT2oo5NcSafBTHI0'
      },
      compute_host_group_id:
        'ocid1.test.oc1..<unique_ID>EXAMPLE-computeHostGroupId-Value',
      compute_cluster_id:
        'ocid1.test.oc1..<unique_ID>EXAMPLE-computeClusterId-Value',
      hostname_label: 'EXAMPLE-hostnameLabel-Value',
      image_id: 'ocid1.test.oc1..<unique_ID>EXAMPLE-imageId-Value',
      ipxe_script: 'EXAMPLE-ipxeScript-Value',
      launch_options:
        OCI::Core::Models::LaunchOptions.new(
          boot_volume_type: 'IDE',
          firmware: 'BIOS',
          network_type: 'E1000',
          remote_data_volume_type: 'SCSI',
          is_pv_encryption_in_transit_enabled: true,
          is_consistent_volume_naming_enabled: true
        ),
      instance_options:
        OCI::Core::Models::InstanceOptions.new(
          are_legacy_imds_endpoints_disabled: false
        ),
      availability_config:
        OCI::Core::Models::LaunchInstanceAvailabilityConfigDetails.new(
          is_live_migration_preferred: false,
          recovery_action: 'RESTORE_INSTANCE'
        ),
      preemptible_instance_config:
        OCI::Core::Models::PreemptibleInstanceConfigDetails.new(
          preemption_action:
            OCI::Core::Models::TerminatePreemptionAction.new(
              type: 'TERMINATE', preserve_boot_volume: false
            )
        ),
      metadata: { 'EXAMPLE_KEY_lAoSt' => 'EXAMPLE_VALUE_wAm5wJWnn3WpkruvKWUH' },
      agent_config:
        OCI::Core::Models::LaunchInstanceAgentConfigDetails.new(
          is_monitoring_disabled: false,
          is_management_disabled: true,
          are_all_plugins_disabled: true,
          plugins_config: [
            OCI::Core::Models::InstanceAgentPluginConfigDetails.new(
              name: 'EXAMPLE-name-Value', desired_state: 'ENABLED'
            )
          ]
        ),
      shape: 'EXAMPLE-shape-Value',
      shape_config:
        OCI::Core::Models::LaunchInstanceShapeConfigDetails.new(
          ocpus: 8590.919,
          vcpus: 327,
          memory_in_gbs: 3445.5132,
          baseline_ocpu_utilization: 'BASELINE_1_2',
          nvmes: 1
        ),
      source_details:
        OCI::Core::Models::InstanceSourceViaImageDetails.new(
          source_type: 'image',
          boot_volume_size_in_gbs: 705,
          image_id: 'ocid1.test.oc1..<unique_ID>EXAMPLE-imageId-Value',
          kms_key_id: 'ocid1.test.oc1..<unique_ID>EXAMPLE-kmsKeyId-Value',
          boot_volume_vpus_per_gb: 642,
          instance_source_image_filter_details:
            OCI::Core::Models::InstanceSourceImageFilterDetails.new(
              compartment_id:
                'ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value',
              defined_tags_filter: {
                'EXAMPLE_KEY_dYIrv' => {
                  'EXAMPLE_KEY_ZD1FH' => 'EXAMPLE--Value'
                }
              },
              operating_system: 'EXAMPLE-operatingSystem-Value',
              operating_system_version: 'EXAMPLE-operatingSystemVersion-Value'
            )
        ),
      subnet_id: 'ocid1.test.oc1..<unique_ID>EXAMPLE-subnetId-Value',
      launch_volume_attachments: [
        OCI::Core::Models::LaunchAttachIScsiVolumeDetails.new(
          type: 'iscsi',
          device: 'EXAMPLE-device-Value',
          display_name: 'EXAMPLE-displayName-Value',
          is_read_only: true,
          is_shareable: true,
          volume_id: 'ocid1.test.oc1..<unique_ID>EXAMPLE-volumeId-Value',
          launch_create_volume_details:
            OCI::Core::Models::LaunchCreateVolumeFromAttributes.new(
              volume_creation_type: 'ATTRIBUTES',
              size_in_gbs: 835,
              compartment_id:
                'ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value',
              display_name: 'EXAMPLE-displayName-Value',
              kms_key_id: 'ocid1.test.oc1..<unique_ID>EXAMPLE-kmsKeyId-Value',
              vpus_per_gb: 727
            ),
          use_chap: true,
          encryption_in_transit_type: 'NONE',
          is_agent_auto_iscsi_login_enabled: false
        )
      ],
      is_pv_encryption_in_transit_enabled: false,
      platform_config:
        OCI::Core::Models::IntelIcelakeBmLaunchInstancePlatformConfig.new(
          type: 'INTEL_ICELAKE_BM',
          is_secure_boot_enabled: false,
          is_trusted_platform_module_enabled: false,
          is_measured_boot_enabled: false,
          is_memory_encryption_enabled: true,
          numa_nodes_per_socket: 'NPS2',
          is_symmetric_multi_threading_enabled: true,
          is_input_output_memory_management_unit_enabled: true,
          percentage_of_cores_enabled: 64,
          config_map: {
            'EXAMPLE_KEY_n8UG2' => 'EXAMPLE_VALUE_DorXnbPTwoTtnfkMDg8e'
          }
        ),
      placement_constraint_details:
        OCI::Core::Models::HostGroupPlacementConstraintDetails.new(
          type: 'HOST_GROUP',
          compute_host_group_id:
            'ocid1.test.oc1..<unique_ID>EXAMPLE-computeHostGroupId-Value'
        ),
      instance_configuration_id:
        'ocid1.test.oc1..<unique_ID>EXAMPLE-instanceConfigurationId-Value',
      licensing_configs: [
        OCI::Core::Models::LaunchInstanceWindowsLicensingConfig.new(
          type: 'WINDOWS', license_type: 'BRING_YOUR_OWN_LICENSE'
        )
      ]
    )
  )

# Get the data from response
puts "#{launch_instance_response.data}"

Was this article helpful?