Skip to content

Commit 30b3077

Browse files
committed
adding example for getting latest image version
1 parent 30dae1f commit 30b3077

File tree

5 files changed

+63
-4
lines changed

5 files changed

+63
-4
lines changed

bmc-examples/src/main/java/CreateInstanceExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016-2017 Oracle and/or its affiliates. All rights reserved.
33
*/
44
import java.util.ArrayList;
55
import java.util.HashMap;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright (c) 2016-2017 Oracle and/or its affiliates. All rights reserved.
3+
*/
4+
import java.util.List;
5+
6+
import com.oracle.bmc.Region;
7+
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
8+
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
9+
import com.oracle.bmc.core.ComputeClient;
10+
import com.oracle.bmc.core.model.Image;
11+
import com.oracle.bmc.core.requests.ListImagesRequest;
12+
import com.oracle.bmc.core.responses.ListImagesResponse;
13+
14+
public class GetImageLatestVersionExample {
15+
16+
public static void main(String[] args) throws Exception {
17+
18+
// TODO: Fill in these values
19+
Region region = Region.US_PHOENIX_1;
20+
String operatingSystem = "Oracle Linux";
21+
String operatingSystemVersion = "6.7";
22+
23+
String configurationFilePath = "~/.oraclebmc/config";
24+
String profile = "DEFAULT";
25+
26+
AuthenticationDetailsProvider provider =
27+
new ConfigFileAuthenticationDetailsProvider(configurationFilePath, profile);
28+
29+
// Find matching images
30+
ComputeClient computeClient = new ComputeClient(provider);
31+
computeClient.setRegion(region);
32+
33+
ListImagesResponse listImagesResponse = computeClient.listImages(
34+
ListImagesRequest.builder()
35+
.compartmentId(provider.getTenantId())
36+
.operatingSystem(operatingSystem)
37+
.operatingSystemVersion(operatingSystemVersion)
38+
.build());
39+
40+
computeClient.close();
41+
42+
List<Image> matchingImages = listImagesResponse.getItems();
43+
44+
if(matchingImages.size() == 0) {
45+
System.out.println("No matching images found.");
46+
}
47+
else {
48+
/*
49+
* Images are sorted by system images first, then custom images, secondarily sorted by image display name.
50+
* Since image display names take the format of "<OS>-<OSVersion>-<Year>.<Month>.<Day>-<Iteration>",
51+
* the first image returned for a list operation sorted by OS and OS version will be the the latest system
52+
* image for that OS / OS version.
53+
*/
54+
Image latestImageVersion = matchingImages.get(0);
55+
56+
System.out.println(latestImageVersion);
57+
}
58+
}
59+
}

bmc-examples/src/main/java/GetInstancePublicIpExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016-2017 Oracle and/or its affiliates. All rights reserved.
33
*/
44
import java.util.List;
55

bmc-examples/src/main/java/ObjectStorageAsyncExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016-2017 Oracle and/or its affiliates. All rights reserved.
33
*/
44
import java.util.concurrent.CountDownLatch;
55

bmc-examples/src/main/java/ObjectStorageSyncExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016-2017 Oracle and/or its affiliates. All rights reserved.
33
*/
44
import com.oracle.bmc.Region;
55
import com.oracle.bmc.auth.AuthenticationDetailsProvider;

0 commit comments

Comments
 (0)