Skip to content

Commit

Permalink
Add a new template option - Image Compartment
Browse files Browse the repository at this point in the history
  • Loading branch information
rwx42 committed Oct 10, 2018
1 parent 9bbe9c5 commit bc9d94d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class BaremetalCloudAgentTemplate implements Describable<BaremetalCloudAg
public final String availableDomain;
public final String vcnId;
public final String subnetId;
public final String imageCompartmentId;
public final String imageId;
public final String shape;
public final String sshPublickey;
Expand Down Expand Up @@ -78,6 +79,7 @@ public BaremetalCloudAgentTemplate(
final String availableDomain,
final String vcnId,
final String subnetId,
final String imageCompartmentId,
final String imageId,
final String shape,
final String sshPublickey,
Expand All @@ -100,6 +102,7 @@ public BaremetalCloudAgentTemplate(
this.availableDomain = availableDomain;
this.vcnId = vcnId;
this.subnetId = subnetId;
this.imageCompartmentId = imageCompartmentId;
this.imageId = imageId;
this.shape = shape;
this.sshPublickey = sshPublickey;
Expand Down Expand Up @@ -137,6 +140,10 @@ public String getSubnet() {
return subnetId;
}

public String getImageCompartmentId() {
return imageCompartmentId;
}

public String getImage() {
return imageId;
}
Expand Down Expand Up @@ -460,6 +467,36 @@ public ListBoxModel doFillAvailableDomainItems(
}
}

public ListBoxModel doFillImageCompartmentIdItems(
@QueryParameter @RelativePath("..") String userId,
@QueryParameter @RelativePath("..") String fingerprint,
@QueryParameter @RelativePath("..") String tenantId,
@QueryParameter @RelativePath("..") String apikey,
@QueryParameter @RelativePath("..") String passphrase,
@QueryParameter @RelativePath("..") String regionId,
@QueryParameter @RelativePath("..") String maxAsyncThreads)
throws IOException, ServletException {
ListBoxModel model = new ListBoxModel();
model.add("<Select image compartmentId>", "");

if (anyRequiredFieldEmpty(userId, fingerprint, tenantId, apikey, regionId)) {
return model;
}

BaremetalCloudClient client = getClient(fingerprint, apikey, passphrase, tenantId, userId, regionId, maxAsyncThreads);

try{
List<Compartment> compartmentIds = client.getCompartmentsList(tenantId);
for (Compartment compartmentId : compartmentIds) {
model.add(compartmentId.getName(), compartmentId.getId());
}
}catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to get compartment list", e);
}

return model;
}

public ListBoxModel doFillImageIdItems(
@QueryParameter @RelativePath("..") String userId,
@QueryParameter @RelativePath("..") String fingerprint,
Expand All @@ -468,7 +505,8 @@ public ListBoxModel doFillImageIdItems(
@QueryParameter @RelativePath("..") String passphrase,
@QueryParameter @RelativePath("..") String regionId,
@QueryParameter @RelativePath("..") String maxAsyncThreads,
@QueryParameter String compartmentId) throws IOException, ServletException {
@QueryParameter String compartmentId,
@QueryParameter String imageCompartmentId) throws IOException, ServletException {
ListBoxModel model = new ListBoxModel();
model.add("<Select an Image>", "");
if (anyRequiredFieldEmpty(userId, fingerprint, tenantId, apikey, regionId, compartmentId)) {
Expand All @@ -479,7 +517,7 @@ public ListBoxModel doFillImageIdItems(

try {
List<String> lstImage = new ArrayList<String>();
List<Image> list = client.getImagesList(compartmentId);
List<Image> list = client.getImagesList(imageCompartmentId);
for (Image imageId : list) {
if (lstImage.indexOf(imageId.getId()) < 0) {
model.add(imageId.getDisplayName(), imageId.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<f:select />
</f:entry>

<f:entry title="${%imageCompartmentId}" field="imageCompartmentId">
<f:select />
</f:entry>

<f:entry title="${%imageId}" field="imageId">
<f:select />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
The compartment from which to select the image.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
<a href="https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/References/images.htm">Oracle-Provided Images</a>
documentation for additional information.</li>

<li>The Drop Down values are in the format - Image(Compartment).</li>
</ul>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static class Builder {
String availableDomain;
String vcnId;
String subnetId;
String imageCompartmentId;
String imageId;
String shape;
String sshPublickey;
Expand Down Expand Up @@ -101,6 +102,11 @@ public Builder usePublicIP(Boolean usePublicIP) {
return this;
}

public Builder imageCompartmentId(String imageCompartmentId) {
this.imageCompartmentId = imageCompartmentId;
return this;
}

public Builder imageId(String imageId) {
this.imageId = imageId;
return this;
Expand Down Expand Up @@ -173,6 +179,7 @@ public TestBaremetalCloudAgentTemplate(Builder builder) {
builder.availableDomain,
builder.vcnId,
builder.subnetId,
builder.imageCompartmentId,
builder.imageId,
builder.shape,
builder.sshPublickey,
Expand Down

0 comments on commit bc9d94d

Please sign in to comment.