I'm creating instance on the Google Compute Engine with jclouds, using the command:
Template template = context.getComputeService().templateBuilder().imageId("debian-7-wheezy-v20150710").build();
Set<? extends NodeMetadata> listNode = context.getComputeService().createNodesInGroup("teste", 1, template);
But is the error below:
2015-08-16 07:27:04 INFO compute:64 - Image debian-7-wheezy-v20150710 not found in the image cache. Trying to get it from the provider...
Exception in thread "main" java.util.NoSuchElementException: imageId(debian-7-wheezy-v20150710) not found
at org.jclouds.compute.domain.internal.TemplateBuilderImpl.throwNoSuchElementExceptionAfterLoggingImageIds(TemplateBuilderImpl.java:764)
at org.jclouds.compute.domain.internal.TemplateBuilderImpl.findImageWithId(TemplateBuilderImpl.java:745)
at org.jclouds.compute.domain.internal.TemplateBuilderImpl.build(TemplateBuilderImpl.java:688)
at br.com.clouddeploy.main.TestGoogle.main(TestGoogle.java:47)
Any suggestion?
If you are using imageId() you probably need to use the full path to the image. Here's how to find it:
% gcloud compute images list --uri | grep debian-7
shows:
https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/backports-debian-7-wheezy-v20150710
https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20150710
So you can use either of these. The one that starts with backports has newer versions of packages, but is still based on Debian 7 Wheezy.
Alternatively, it looks like jclouds has the ability to do this URL creation on its own, but instead of using imageId(), you should use (see GitHub code example):
ComputeService compute = initComputeService(account, credentials);
[...]
TemplateBuilder templateBuilder = compute.templateBuilder();
templateBuilder.fromImage(compute
.getImage("debian-7-wheezy-v20140408"));
Related
I want to use python oci package to get information about environment.
how to list all IPs addresses (both public or private) attached to compute node?
list_instances() does not provide this part of compute details unfortunately.
thanks.
As shared by #Char above, this oci-python-sdk example should help you here.
You can find a list of all supported services by SDK for Python here - https://docs.cloud.oracle.com/en-us/iaas/Content/API/SDKDocs/pythonsdk.htm
Additionally, full documentation for OCI Python SDK can be found here - https://docs.cloud.oracle.com/en-us/iaas/tools/python/2.21.5/
Please use this code. Basically you have to lookup VNIC Attachment object and filter VNIC_ID based on InstanceId. VNIC_ID can be used for looking up IP Addresses subsequently.
I have used data[0] to indicate the first attachment. You could use a loop to go through all attachments and print the IP.
compute_client = oci.core.ComputeClient(config={}, signer=signer)
network_client = oci.core.VirtualNetworkClient(
config={}, signer=signer)
vnic_id = compute_client.list_vnic_attachments(
cd_compartment_id, instance_id=instanceId).data[0].vnic_id
private_ip = network_client.get_vnic(vnic_id).data.private_ip
Assuming that you have the display name of an OCI compute instance and you need its private and public IP addresses, provided that you already created an API key in your profile and that you configured your ~/.oci/config with valid pem private key downloaded when creating the API Key, the following Python code can help:
import oci
display_name = "your display name"
config = oci.config.from_file()
identity = oci.identity.IdentityClient(config)
user = identity.get_user(config["user"]).data
instances = oci.core.ComputeClient(config).list_instances(
compartment_id=user.compartment_id).data
instance_id = {i.display_name: i.id for i in instances}[display_name]
compute_client = oci.core.ComputeClient(config)
vnic_data = compute_client.list_vnic_attachments(
compartment_id=user.compartment_id, instance_id=instance_id).data
network_client = oci.core.VirtualNetworkClient(config)
vnic_list = [network_client.get_vnic(vnic_attachment.vnic_id).data
for vnic_attachment in vnic_data]
public_ip = {i.display_name: i.public_ip for i in vnic_list}[display_name]
private_ip = {i.display_name: i.private_ip for i in vnic_list}[display_name]
print(public_ip, private_ip)
This implies:
pip3 install oci oci-cli
I am trying to create an OCI instance with the Java SDK. I am getting an error in routeRules.
When I commented the following line, I was able to create an instance. But in that machines route is not enabled.
addInternetGatewayToRouteTable(vcnClient, compartmentId, vcn.getDefaultRouteTableId(), internetGateway);
https://github.com/oracle/oci-java-sdk/blob/master/bmc-examples/src/main/java/CreateInstanceExample.java
Exception in thread "main" com.oracle.bmc.model.BmcException: (400, InvalidParameter, false) routeRules[0].networkEntityId may not be null (opc-request-id: 6BC8A182852240F8AFFD1EB279CFF901/AD5BF82603D64DA298976FCFE83871F6/9398B04078B0435A8FA68FEA7307CC99)
at com.oracle.bmc.http.internal.ResponseHelper.throwIfNotSuccessful(ResponseHelper.java:120)
at com.oracle.bmc.http.internal.ResponseConversionFunctionFactory$ValidatingParseResponseFunction.apply(ResponseConversionFunctionFactory.java:86)
at com.oracle.bmc.http.internal.ResponseConversionFunctionFactory$ValidatingParseResponseFunction.apply(ResponseConversionFunctionFactory.java:82)
at com.oracle.bmc.core.internal.http.UpdateRouteTableConverter$1.apply(UpdateRouteTableConverter.java:70)
at com.oracle.bmc.core.internal.http.UpdateRouteTableConverter$1.apply(UpdateRouteTableConverter.java:55)
at com.oracle.bmc.core.VirtualNetworkClient.updateRouteTable(VirtualNetworkClient.java:3325)
at CreateInstanceExample.addInternetGatewayToRouteTable(CreateInstanceExample.java:295)
at CreateInstanceExample.main(CreateInstanceExample.java:146)
There is a bug in the code, you can replace destination in the addInternetGatewayToRouteTable(..) method
RouteRule internetAccessRoute =
RouteRule.builder()
.cidrBlock("0.0.0.0/0")
.destination(internetGateway.getId())
.build();
in line 295 with networkEntityId:
RouteRule internetAccessRoute =
RouteRule.builder()
.cidrBlock("0.0.0.0/0")
.networkEntityId(internetGateway.getId())
.build();
You can see from the REST APIs here which parameters are required to create a route rule in a route table.
The example seems to be based on a deprecated version of calling the RouteRule builder.
I see that the POSTGRES database option for gce sql is still in BETA, just looking for confermation that the issue mentioned below is an issue with the API and not something stupid I've overlooked.
gcloud sql instances create example-db --activation-policy=ALWAYS --tier="db-n1-standard-1" --pricing-plan="PER_USE" --region="asia-east1" --gce-zone="asia-east1-a" --database-version=POSTGRES_9_6
HTTPError 400: Invalid value for: POSTGRES_9_6 is not a valid value
Documentation says that this is a valid option:
- https://cloud.google.com/sdk/gcloud/reference/sql/instances/create
Found more documentation that explains I needed to use the gcloud beta command syntax.
https://cloud.google.com/sql/docs/postgres/create-instance
Actual Working Example
gcloud beta sql instances create example-db --activation-policy=ALWAYS --pricing-plan="PER_USE" --region="asia-east1" --gce-zone="asia-east1-a" --cpu=2 --memory=3840MiB --database-version="POSTGRES_9_6"
With the gcloud command line tool I can do:
$ gcloud compute instances list --filter='tags.items:development'
The documentation claims: "..you can also filter on nested fields. For example, you could filter on instances that have set the scheduling.automaticRestart field to true. Use filtering on nested fields to take advantage of labels to organize and search for results based on label values." But no examples are provided, so it's not clear how one actually goes about this.
I've tried labels.development eq *.*, labels eq *development*, labels:development et al.. I've also tried setting the verbosity of the of the command line client to info and looking through the output, as well as monitoring requests that go to the API from the Compute Engine web console, but neither has gotten me anywhere.
Finding Tags with regular expression filters
I'm struggling with the same issue but I think that regular expressions solve the problem.
I have many instances with multiple tags but I can search across all tags with the '~' operator e.g. to find all servers with the production tag:
gcloud compute instances list --filter='tags.items~^production$'
For many servers the 'production' tag is the third entry in tags.items yet the regexp finds it.
This seems to work but I can't find any documentation that specifically says that it should work. The nearest is the section on topic filters which mentions this
key ~ value True if key matches the RE (regular expression) pattern
value.
You can also search for multiple tags
gcloud compute instances list --filter='tags.items~^production$ AND tags.items~^european$'
which would find all servers with the two tags 'production' and 'european'
Tags v Custom metadata
If you want something a bit more flexible than tags (which can only be present or missing), you can attach your own custom multi-valued metadata to an instance (via the UI, command-line or API). You can then search for particular values of that item.
For example suppose I have different instances supporting eCommerce for different brands, I could attach a custom 'brand' metadata item to each server and then find all of the servers which run my "Coca-Cola" brands via ..
gcloud compute instances list --filter="metadata.items.key['brand']['value']='Coca-Cola'"
... and my 'Pepsi Cola' servers with ...
gcloud compute instances list --filter="metadata.items.key['brand']['value']='Pepsi Cola'"
Finding Metadata with regular expression filters
You probably guessed this already but the regular expression operator also works with metadata filters so you can do
gcloud compute instances list --filter="metadata.items.key['brand']['value']~'Cola'"
As explained here you can use the following syntax using gcloud cli:
gcloud compute instances list --filter labels.env=dev
Multi Filtering example that I'm using:
gcloud compute instances list --filter="zone:( europe-west1-d )" --filter="name:( testvm )" --filter labels.group=devops --filter labels.environment_type=production
Add instance metadata MyKey=MyValue for gke-cluster-asia-eas-default-pool-dc8f484c-knbs:
gcloud compute instances add-metadata gke-cluster-asia-eas-default-pool-dc8f484c-knbs --metadata=MyKey=MyValue
Display all instances with MyKey=MyValue:
gcloud compute instances list --filter="metadata.items.key['MyKey'][value]='MyValue'"
Display all instances that belong to the cluster cluster-asia-east1-a:
gcloud compute instances list --filter="metadata.items.key['cluster-name'][value]='cluster-asia-east1-a'"
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
gke-cluster-asia-eas-default-pool-dc8f484c-knbs asia-east1-a n1-standard-1 10.140.0.2 104.155.227.25 RUNNING
gke-cluster-asia-eas-default-pool-dc8f484c-x8cv asia-east1-a n1-standard-1 10.140.0.3 104.199.226.16 RUNNING
gke-cluster-asia-eas-default-pool-dc8f484c-z5wv asia-east1-a n1-standard-1 10.140.0.4 104.199.134.9 RUNNING
i'm trying to create a VM using libcloud with auto delete feature. The thing is that it only works for boot disks.
Example:
new_node = driver.create_node("my_node_str", size, get_root_snapshot(driver), location,ex_service_accounts=sa_scopes, ex_disk_auto_delete=True, ...
Then I attach a disk:
driver.attach_volume(my_node,...,ex_boot=False, ex_auto_delete=True)
So i go to GCE and this volume auto delete is turned OFF
So, i try to change it "manually" using libcloud:
conn.ex_set_volume_auto_delete(vol, node)
And I get the error :
libcloud.common.google.GoogleBaseError: u"Invalid value for field 'disk': 'myvolume1-worker-disk'
But the disk is created, attached and it is working on my VM.
Debugging libloud everything seems to be ok acording to documentation (https://cloud.google.com/compute/docs/reference/latest/instances/setDiskAutoDelete):
It calls:
u'/zones/us-central1-b/instances/myinstancename/setDiskAutoDelete'
With parameters:
'deviceName': volume.name, 'autoDelete': auto_delete,
any clues?
It looks like there may be a bug with attach_volume. I'll do a bit of testing and get that fixed up if so.
Regarding using ex_set_volume_auto_delete, you need to pass in a StorageVolume object. It looks like you are just passing in a string (the name of the disk).
You could try,
disk_obj = driver.ex_get_volume('string-name-of-disk')
driver.ex_set_volume_auto_delete(node_obj, disk_obj, ex_auto_delete=True)
I'll follow up about the first issue when I look into it more.