I am trying to detach a disk from a stopped instance which is currently holding the disk. here's how I am doing it currently.
def detach_disk_from_instance(disk_name, zone=GCLOUD_ZONE):
disk_info = get_disk_info(disk_name=disk_name, zone=zone)
if disk_info.get('users'):
instance_name = disk_info['users'][0].rsplit('/').pop()
logger.info("detatching disk : {} from instance : {}".format(disk_name, instance_name))
request = compute.instances().detachDisk(
project=GCLOUD_PROJECT_NAME, zone=zone, instance=instance_name, deviceName=disk_name)
return make_http_request(request, {})
def wait_for_operation(operation, zone=GCLOUD_ZONE, worker=1):
logger.info('Waiting for operation {} to finish...'.format(operation))
with ThreadPoolExecutor(worker) as executor:
future = executor.submit(_check_operation_status, operation=operation, zone=zone)
wait([future])
return future.result()
req = detach_disk_from_instance(disk_name='test-disk')
wait_for_operation(operation=req['name'])
above code works if instance which is holding the disk is currently running.
but it doesn't work if instance is stopped. I get the following error when I try to detach disk from a stopped instance.
{'errors': [{'message': "No attached disk found with device name
'test-disk'", 'code': 'INVALID_USAGE'}]}
and I assure you that disk is still attached to the instance and gcp dashboard also shows that.
TL;DR - You're passing the name of the disk resource instead of the device name by which the disk is attached to the instance.
In the instances.attachDisk request to attach a disk to a VM instance you can specify the device name in the deviceName field of the request.
deviceName
string
Specifies a unique device name of your choice that
is reflected into the /dev/disk/by-id/google-* tree of a Linux
operating system running within the instance. This name can be used to
reference the device for mounting, resizing, and so on, from within
the instance.
If not specified, the server chooses a default device name to apply to
this disk, in the form persistent-disks-x, where x is a number
assigned by Google Compute Engine. This field is only applicable for
persistent disks.
You will need to use this name as the deviceName query parameter for the instances.detachDisk request.
Required query parameters
deviceName
string
Disk device name to detach.
As mentioned in the doc, if you did not specify a device name while attaching the disk GCE generates a device name in the form persistent-disks-x and you will have to specify this name.
Related
I have a scheduled script execution that needs to persist a value between runs. It is updated with each run. Using gs.setProperty seemed like the natural place until I came across this:
Care should be taken when setting system properties (sys_properties)
using this method as it causes a system-wide cache flush. Each flush
can cause system degradation while the caches rebuild. If a value must
be updated often, it should not be stored as a system property. In
general, you should only place values in the sys_properties table that
do not frequently change.
Creating a separate table to store a single scalar value seems like overkill. Is there a better place to store it?
You could set a preference if you need it in the instance. Another place could be the events table. Log the event with the data in parm1 or parm2 and on next run query the most recent event.
I'd avoid making a table as that has cost implications for some clients. I agree with the sys_properties.
var encrypter = new GlideEncrypter();
var encrypted = encrypter.encrypt('Super Secret Phrase');
gs.info('encrypted: ' + encrypted);
var decrypted = encrypter.decrypt(encrypted);
gs.info('decrypted: ' + decrypted);
/**
*** Script: encrypted: g/bXLJHa7xNRMKZEo5q/YtLMEdse36ED
*** Script: decrypted: Super Secret Phrase
*/
This way only administrators could really read this data. Also if I recall correctly, the sysevent table is cleared after 7 days. You could have the job remove the event as soon as it has it in memory.
I'm trying to create spot instances in different region using boto3.
My default regions defined as us-east-1.
When I'm trying to create the spot instances in different region from the default one , an exception is thrown with this message:
botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the RequestSpotInstances operation: Invalid availability zone: [eu-west-2b]
The instances created using this code snippet:
for idx in range(len(regions)):
client.request_spot_instances(
DryRun=False,
SpotPrice=price_bids,
InstanceCount=number_of_instances,
LaunchSpecification=
{
'ImageId': ami_id,
'KeyName': 'matrix',
'SecurityGroupIds': ['sg-5f07f52c'],
'SecurityGroups': ['MatrixSG'],
'InstanceType': machine_type,
'Placement':
{
'AvailabilityZone': regions[idx],
},
},
)
I assume that your regions list actually contains a list of Availability Zones rather than regions (since it says 'AvailabilityZone': regions[idx]).
Each AWS region operates independently. When making a connection to an AWS service, you must connect to the specific service in a specific region.
For example:
client = boto3.client('ec2')
This connects to EC2 in your default region.
Alternatively, you can specify a region:
client = boto3.client('ec2', region_name = 'eu-west-2')
You are receiving the Invalid availability zone error because your client is connected to a region (eg us-east-1) but is referencing an Availability Zone that is in a different region (eg eu-west-2b).
Your code is only creating the client once, but is attempting to connect to multiple regions. The solution is to create a new client connection for the region you wish to use. If your loop connects to multiple regions, then the client should be defined within the loop rather than outside the loop.
In Zabbix 3.2, I am setting up a screen for a new server, and want to configure a clock that shows the local time from the monitored host.
This is how I configured the screen element:
I have checked in Latest Data that the Host localtime is being received (it is).
However, when I save this screen configuration, the display just says, "No data":
How do you display the time on the monitored host?
In order for this screen element to work, you have to use system.localtime[local] item (which returns a string in a certain format, see item documentation) instead of the default system.localtime (which returns an integer timestamp).
The system.localtime[local] item returns a string like the following:
2016-12-07,09:36:59.688,+02:00
It allows the frontend to nicely display the time zone:
I'm getting error for "SNMPv3" of invalid engine ID? what causes this error usually?
it perfectly works when i select no auth,no priv. but for other two options of auth,no priv and auth,priv it gives error of invalid engine id.
ManageEngine MibBrowser supports auto-discovery of SnmpEngineID, EngineBoots and EngineTime from an Authoritative SNMP Engine.
If user has enabled the "Set EngineID For Adding V3 entry" and entered SNMPV3 user details with EngineID parameter, MibBrowser displays the message received from Agent.
As per RFC3414, If the value of the msgAuthoritativeEngineID
field in the securityParameters is unknown then:
a) a non-authoritative SNMP engine that performs discovery may
optionally create a new entry in its Local Configuration Datastore
(LCD) and continue processing;
or
b) the usmStatsUnknownEngineIDs counter is incremented, and an error
indication (unknownEngineID) together with the OID and value of the
incremented counter are returned to the calling module.
Note in the event that a zero-length or other illegally sized
msgAuthoritativeEngineID is received,b) should be chosen to facilitate
engineID discovery. Otherwise, the choice between a) and b) is an
implementation issue.
If Authoritative SNMP Engine returns "unKnownEngineID OID"(.1.3.6.1.6.3.15.1.1.4.0) with incremental counter value to manager. Then, Mibbrowser displays the "Invalid EngineID" error.
Regards,
ManageEngine
I created a private image of a Google compute engine persistent disk, called primecoin01.
Later on, I'm trying to create a new image. It fails by saying the regexp is invalid both in listing the images and during gcloud.compute.instances.delete - the 1st step in using my persistent disk to create an image. It let me create the image name and now I'm unable to use the commands gcloud compute images list or gcloud compute instances delete instance-0 --keep-disks boot. I do not know a way to delete this image from my list.
primecoin01 certainly meets the regular expression criteria, and I have no clue why it named the image apparently ``primecoin01 All help greatly appreciated.
Details below:
C:\Program Files\Google\Cloud SDK>gcloud compute images list
NAME PROJECT ALIAS DEPRECATED STATUS
centos-6-v20141021 centos-cloud centos-6 READY
centos-7-v20141021 centos-cloud centos-7 READY
coreos-alpha-494-0-0-v20141108 coreos-cloud READY
coreos-beta-444-5-0-v20141016 coreos-cloud READY
coreos-stable-444-5-0-v20141016 coreos-cloud coreos READY
backports-debian-7-wheezy-v20141021 debian-cloud debian-7-backports READY
debian-7-wheezy-v20141021 debian-cloud debian-7 READY
container-vm-v20141016 google-containers container-vm READY
opensuse-13-1-v20141102 opensuse-cloud opensuse-13 READY
rhel-6-v20141021 rhel-cloud rhel-6 READY
rhel-7-v20141021 rhel-cloud rhel-7 READY
sles-11-sp3-v20140930 suse-cloud sles-11 READY
sles-11-sp3-v20141105 suse-cloud sles-11 READY
sles-12-v20141023 suse-cloud READY
ERROR: (gcloud.compute.images.list) Some requests did not succeed:
- Invalid value '``primecoin01'. Values must match the following regular expression: '(?:(?:[-a-z0-9]{1,63}\.)*(?:[a-z]
(?:[-a-z0-9]{0,61}[a-z0-9])?):)?(?:[0-9]{1,19}|(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?))'
and
C:\Program Files\Google\Cloud SDK>gcloud compute instances delete instance-0 --keep-disks boot
ERROR: (gcloud.compute.instances.delete) Unable to fetch a list of zones. Specifying [--zone] may fix this issue:
- Invalid value '``primecoin01'. Values must match the following regular expression: '(?:(?:[-a-z0-9]{1,63}\.)*(?:[a-z] (?:[-a-z0-9]{0,61}[a-z0-9])?):)?(?:[0-9]{1,19}|(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?))'
and
C:\Program Files\Google\Cloud SDK>gcloud compute instances delete instance-0 --keep-disks boot --zone us-central1-b
The following instances will be deleted. Attached disks configured to
be auto-deleted will be deleted unless they are attached to any other
instances. Deleting a disk is irreversible and any data on the disk
will be lost.
- [instance-0] in [us-central1-b]
Do you want to continue (Y/n)? y
ERROR: (gcloud.compute.instances.delete) Failed to fetch some instances:
- Invalid value '``primecoin01'. Values must match the following regular expression: '(?:(?:[-a-z0-9]{1,63}\.)*(?:[a-z]
(?:[-a-z0-9]{0,61}[a-z0-9])?):)?(?:[0-9]{1,19}|(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?))'
It seems to be a validation error when creating the disk and the name is not correct. Are you still having the same issue?
A way to create a 'snapshot' of your disk will be to use the dd Linux command to burn your image and then tar the file to create an image from this file.