public String getFirstVpcOfferingId() { Multimap<String, String> params = ArrayListMultimap.create(); params.put("command", "listVPCOfferings"); params.put("apiKey", this.apiKey); params.put("response", "json"); HttpRequest request = HttpRequest.builder() .method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build(); request = getQuerySigner().filter(request); HttpToolResponse response = HttpUtil.invoke(request); JsonElement offers = json(response); LOG.debug("LIST VPC OFFERS\n" + pretty(offers)); String id = offers.getAsJsonObject().get("listvpcofferingsresponse"). getAsJsonObject().get("vpcoffering").getAsJsonArray(). get(0).getAsJsonObject().get("id").getAsString(); LOG.debug(" using first VPC offering ID: " + id); return id; }
.method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build();
protected JsonArray listVpcsJson() { Multimap<String, String> params = ArrayListMultimap.create(); params.put("command", "listVPCs"); if (accAndDomain.isPresent()) { params.put("account", accAndDomain.get().account); params.put("domainid", accAndDomain.get().domainId); } params.put("apiKey", this.apiKey); params.put("response", "json"); HttpRequest request = HttpRequest.builder() .method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build(); request = getQuerySigner().filter(request); HttpToolResponse response = HttpUtil.invoke(request); JsonElement jr = json(response); LOG.debug(pretty(jr)); JsonElement vpcs = jr.getAsJsonObject().get("listvpcsresponse").getAsJsonObject().get("vpc"); return vpcs == null ? null : vpcs.getAsJsonArray(); }
.method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build();
.method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build();
.method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build();
.method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build();
.method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build();
public PublicIPAddress createIpAddressForVpc(String vpcId) { Multimap<String, String> params = ArrayListMultimap.create(); params.put("command", "associateIpAddress"); params.put("vpcid", vpcId); if (accAndDomain.isPresent()) { params.put("account", accAndDomain.get().account); params.put("domainid", accAndDomain.get().domainId); } params.put("apiKey", this.apiKey); params.put("response", "json"); LOG.debug("associateIpAddress GET " + params); HttpRequest request = HttpRequest.builder() .method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build(); request = getQuerySigner().filter(request); HttpToolResponse response = HttpUtil.invoke(request); // TODO does non-2xx response need to be handled separately ? try { String result = waitForJobCompletion(response, "createIpAddressForVpc("+vpcId+")"); return getCloudstackGlobalClient().getAddressApi().getPublicIPAddress(result); } catch (InterruptedException e) { throw Exceptions.propagate(e); } }
public String createVpc(String cidr, String displayText, String name, String vpcOfferingId, String zoneId) { Multimap<String, String> params = ArrayListMultimap.create(); params.put("command", "createVPC"); params.put("cidr", cidr); params.put("displayText", displayText); params.put("name", name); params.put("vpcOfferingId", vpcOfferingId); params.put("zoneId", zoneId); if (accAndDomain.isPresent()) { params.put("account", accAndDomain.get().account); params.put("domainid", accAndDomain.get().domainId); } params.put("apiKey", this.apiKey); params.put("response", "json"); HttpRequest request = HttpRequest.builder() .method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build(); request = getQuerySigner().filter(request); HttpToolResponse response = HttpUtil.invoke(request); // todo: handle non-2xx response try { return waitForJobCompletion(response, "createVpc("+cidr+", "+displayText+", "+name+", "+vpcOfferingId+", "+zoneId+")"); } catch (InterruptedException e) { throw Exceptions.propagate(e); } }
public PublicIPAddress createIpAddressForNetwork(String networkId) { Multimap<String, String> params = ArrayListMultimap.create(); params.put("command", "associateIpAddress"); params.put("networkid", networkId); if (accAndDomain.isPresent()) { params.put("account", accAndDomain.get().account); params.put("domainid", accAndDomain.get().domainId); } params.put("apiKey", this.apiKey); params.put("response", "json"); LOG.debug("associateIpAddress GET " + params); HttpRequest request = HttpRequest.builder() .method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build(); request = getQuerySigner().filter(request); HttpToolResponse response = HttpUtil.invoke(request); // TODO does non-2xx response need to be handled separately ? try { String result = waitForJobCompletion(response, "createIpAddressForNetwork("+networkId+")"); return getCloudstackGlobalClient().getAddressApi().getPublicIPAddress(result); } catch (InterruptedException e) { throw Exceptions.propagate(e); } }
public String deleteVpc(String vpcId) { Multimap<String, String> params = ArrayListMultimap.create(); params.put("command", "deleteVPC"); params.put("id", vpcId); params.put("apiKey", this.apiKey); params.put("response", "json"); HttpRequest request = HttpRequest.builder() .method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build(); request = getQuerySigner().filter(request); HttpToolResponse response = HttpUtil.invoke(request); // todo: handle non-2xx response try { return waitForJobCompletion(response, "deleteVpc("+vpcId+")"); } catch (InterruptedException e) { throw Exceptions.propagate(e); } }
protected JsonElement listPublicIpAddressesAtVpc(String vpcId) { Multimap<String, String> params = ArrayListMultimap.create(); params.put("command", "listPublicIpAddresses"); params.put("vpcid", vpcId); if (accAndDomain.isPresent()) { params.put("account", accAndDomain.get().account); params.put("domainid", accAndDomain.get().domainId); } params.put("apiKey", this.apiKey); params.put("response", "json"); HttpRequest request = HttpRequest.builder() .method("GET") .endpoint(this.endpoint) .addQueryParams(params) .addHeader("Accept", "application/json") .build(); request = getQuerySigner().filter(request); HttpToolResponse response = HttpUtil.invoke(request); JsonElement jr = json(response); LOG.debug(pretty(jr)); return jr.getAsJsonObject().get("listpublicipaddressesresponse"); }
private HttpRequest sign(String method, String container, String name, GetOptions options, long expires, @Nullable String contentType) { checkNotNull(container, "container"); checkNotNull(name, "name"); URI url = Uris.uriBuilder(storageUrl).appendPath(container).appendPath(name).build(); String signature = signer.sign(method, url.getPath(), expires); HttpRequest.Builder builder = HttpRequest.builder() .method(method) .endpoint(url) .addQueryParams(options.buildQueryParameters()) .addQueryParam("temp_url_sig", signature) .addQueryParam("temp_url_expires", String.valueOf(expires)) .headers(options.buildRequestHeaders()); if (contentType != null) { builder.replaceHeader(HttpHeaders.CONTENT_TYPE, contentType); } return builder.build(); } }
private HttpRequest sign(String method, String container, String name, GetOptions options, long expires, @Nullable String contentType) { checkNotNull(container, "container"); checkNotNull(name, "name"); URI url = Uris.uriBuilder(storageUrl).appendPath(container).appendPath(name).build(); String signature = signer.sign(method, url.getPath(), expires); HttpRequest.Builder builder = HttpRequest.builder() .method(method) .endpoint(url) .addQueryParams(options.buildQueryParameters()) .addQueryParam("temp_url_sig", signature) .addQueryParam("temp_url_expires", String.valueOf(expires)) .headers(options.buildRequestHeaders()); if (contentType != null) { builder.replaceHeader(HttpHeaders.CONTENT_TYPE, contentType); } return builder.build(); } }
private HttpRequest sign(String method, String container, String name, GetOptions options, long expires) { checkNotNull(container, "container"); checkNotNull(name, "name"); URI url = Uris.uriBuilder(storageUrl).appendPath(container).appendPath(name).build(); String signature = signer.sign(method, url.getPath(), expires); return HttpRequest.builder() .method(method) .endpoint(url) .addQueryParams(options.buildQueryParameters()) .addQueryParam("temp_url_sig", signature) .addQueryParam("temp_url_expires", String.valueOf(expires)) .headers(options.buildRequestHeaders()).build(); } }