Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EC2[EBS] Allow assigning existing volume to the resource #1128

Merged
merged 2 commits into from Apr 19, 2019

Conversation

PsyanticY
Copy link
Contributor

No description provided.

def get_physical_spec(self):
physical = {}
if self.volume_id:
physical['volumeId'] = self.volume_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea where this can be used ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to use it to to tweak the show-physical-backup function to get it to generate a file to override volumes with snapshots/other volumes

if defn.snapshot:
self.log("creating EBS volume of {0} GiB from snapshot ‘{1}’...".format(defn.size, defn.snapshot))
if defn.volume_id != "":
vol_id = defn.volume_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the other volume attributes ? I think it'd be better to implement a _check method that pulls the volume attribute and persist to the state so in case it's an existent volume we run self._check() first

@AmineChikhaoui
Copy link
Member

Btw I like the idea in general but sometimes I think it should be implemented at the resource level where we'll have something like terraform import

@@ -29,6 +29,16 @@ with lib;
description = "The AWS Access Key ID.";
};

volumeId = mkOption {
default = "test123";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there shouldn't be a default value here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup and i missed to remove that since i used it for testing. ty

example = "vol-abc123";
type = types.str;
description = ''
The volume ID that will be set by nixops or overriden
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent with 2 spaces

self._conn_boto3 = nixops.ec2_utils.connect_ec2_boto3(region, self.access_key_id)
return self._conn_boto3

def _check(self, defn):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this won't run during nixops check as that expects a method _check() that doesn't get any arguments

def _check(self, defn):
self.connect_boto3(defn.region)
try:
_vol = self._conn_boto3.describe_volumes(VolumeIds=[defn.volume_id])['Volumes'][0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also what if there is no volume_id in the definition like the old behavior ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function should not run when there is no defined volume_id. the function should not run during a nixops check so i assume i should change the name if _check if reserved ?

@PsyanticY PsyanticY changed the title Show physical for ebs volumes and allow assigning existing volume to the resource EC2[EBS] Allow assigning existing volume to the resource Apr 18, 2019
@PsyanticY PsyanticY force-pushed the ebsVolumes branch 2 times, most recently from bbc6df3 to c93a99b Compare April 19, 2019 20:04
PsyanticY and others added 2 commits April 19, 2019 17:54
@AmineChikhaoui AmineChikhaoui merged commit 8d5f239 into NixOS:master Apr 19, 2019
@PsyanticY PsyanticY deleted the ebsVolumes branch April 19, 2019 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants