Skip to content

Instantly share code, notes, and snippets.

@jodoglevy
Created February 24, 2017 00:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jodoglevy/e1208daae326548bc03b5fd7c5190c6a to your computer and use it in GitHub Desktop.
Save jodoglevy/e1208daae326548bc03b5fd7c5190c6a to your computer and use it in GitHub Desktop.
public static void main(String[] args) throws Exception {
String compartmentId = "SOME OCID";
String instanceDisplayName = "SOME NAME";
String networkCidrBlock = "10.0.0.0/16";
String sshPublicKey =
"ssh-rsa AAAAB3NzaC1y...key shortened for example...fdK/ABqxgH7sy3AWgBjfj some description";
String subnetDisplayName = instanceDisplayName + "-subnet";
String vcnDisplayName = instanceDisplayName + "-vcn";
String internetGatewayDisplayName = instanceDisplayName + "-internet-gateway";
String configurationFilePath = "~/.oraclebmc/config";
String profile = "DEFAULT";
AuthenticationDetailsProvider provider =
new ConfigFileAuthenticationDetailsProvider(configurationFilePath, profile);
ComputeClient computeClient = new ComputeClient(provider);
VirtualNetworkClient vcnClient = new VirtualNetworkClient(provider);
vcnClient.setRegion(Region.US_PHOENIX_1);
computeClient.setRegion(Region.US_PHOENIX_1);
List<AvailabilityDomain> availabilityDomains =
getAvailabilityDomains(provider, compartmentId);
AvailabilityDomain adToUse = availabilityDomains.get(0);
List<Image> images = getImages(provider, computeClient, compartmentId);
List<Shape> shapes = getShapes(provider, computeClient, compartmentId);
Vcn vcn = createVcn(vcnClient, compartmentId, vcnDisplayName, networkCidrBlock);
InternetGateway internetGateway =
createInternetGateway(
vcnClient, compartmentId, internetGatewayDisplayName, vcn.getId());
addInternetGatewayToRouteTable(
vcnClient, compartmentId, vcn.getDefaultRouteTableId(), internetGateway);
Subnet subnet =
createSubnet(
vcnClient,
compartmentId,
adToUse,
subnetDisplayName,
networkCidrBlock,
vcn.getId(),
vcn.getDefaultRouteTableId());
Instance instance =
createInstance(
computeClient,
compartmentId,
adToUse,
instanceDisplayName,
images.get(0),
shapes.get(0),
subnet,
sshPublicKey);
System.out.println("Instance is provisioning...");
instance = waitForInstanceProvisioningToComplete(computeClient, instance.getId());
computeClient.close();
vcnClient.close();
System.out.println("Instance is provisioned:");
System.out.println(instance);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment