// 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.DataccService;
using Oci.Common;
using Oci.Common.Auth;
namespace Oci.Sdk.DotNet.Example.Datacc
{
public class CreateVmInstanceExample
{
public static async Task Main()
{
// Create a request and dependent object(s).
var createVmInstanceDetails = new Oci.DataccService.Models.CreateVmInstanceDetails
{
CompartmentId = "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
DisplayName = "EXAMPLE-displayName-Value",
Description = "EXAMPLE-description-Value",
InfrastructureId = "ocid1.test.oc1..<unique_ID>EXAMPLE-infrastructureId-Value",
CpusEnabled = 542,
MemorySizeInGBs = 478.2957,
BootStorageSizeInGBs = 5735.3555,
DataStorageSizeInGBs = 7840.9966,
ImageId = "ocid1.test.oc1..<unique_ID>EXAMPLE-imageId-Value",
ServerId = "ocid1.test.oc1..<unique_ID>EXAMPLE-serverId-Value",
SshPublicKeys = new List<string>
{
"EXAMPLE--Value"
},
DomainName = "EXAMPLE-domainName-Value",
TimeZone = "EXAMPLE-timeZone-Value",
DnsServers = new List<string>
{
"EXAMPLE--Value"
},
NtpServers = new List<string>
{
"EXAMPLE--Value"
},
Hostname = "EXAMPLE-hostname-Value",
IpAddress = "EXAMPLE-ipAddress-Value",
Netmask = "EXAMPLE-netmask-Value",
Gateway = "EXAMPLE-gateway-Value",
VlanId = "ocid1.test.oc1..<unique_ID>EXAMPLE-vlanId-Value",
Userdata = "EXAMPLE-userdata-Value",
Metadata = new Dictionary<string, string>()
{
{
"EXAMPLE_KEY_c592r",
"EXAMPLE_VALUE_9ySZCuw2wfW5T2ZUngxT"
}
},
VmNetworkId = "ocid1.test.oc1..<unique_ID>EXAMPLE-vmNetworkId-Value",
DefinedTags = new Dictionary<string, Dictionary<string, Object>>()
{
{
"EXAMPLE_KEY_0tpVL",
new Dictionary<string, Object>()
{
{
"EXAMPLE_KEY_kZLBA",
"EXAMPLE--Value"
}
}
}
},
FreeformTags = new Dictionary<string, string>()
{
{
"EXAMPLE_KEY_3vgdD",
"EXAMPLE_VALUE_LWVIqzx7v3Ct6q9kmTIS"
}
},
SystemTags = new Dictionary<string, Dictionary<string, Object>>()
{
{
"EXAMPLE_KEY_fRI9O",
new Dictionary<string, Object>()
{
{
"EXAMPLE_KEY_i36Kx",
"EXAMPLE--Value"
}
}
}
}
};
var createVmInstanceRequest = new Oci.DataccService.Requests.CreateVmInstanceRequest
{
CreateVmInstanceDetails = createVmInstanceDetails,
OpcRetryToken = "EXAMPLE-opcRetryToken-Value",
OpcRequestId = "NONLF5P3VCFZ6LZGH9BL<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 BaseinfraClient(provider, new ClientConfiguration()))
{
var response = await client.CreateVmInstance(createVmInstanceRequest);
// Retrieve value from the response.
var id = response.VmInstance.Id;
}
}
catch (Exception e)
{
Console.WriteLine($"CreateVmInstance Failed with {e.Message}");
throw e;
}
}
}
}