Struct Manager

Source
pub struct Manager {
    pub region: String,
    pub cli: Client,
}
Expand description

Implements AWS EC2 manager.

Fields§

§region: String§cli: Client

Implementations§

Source§

impl Manager

Source

pub fn new(shared_config: &AwsSdkConfig) -> Self

Source

pub async fn import_key( &self, key_name: &str, pubkey_path: &str, ) -> Result<String>

Imports a public key to EC2 key.

Source

pub async fn create_key_pair( &self, key_name: &str, key_path: &str, ) -> Result<()>

Creates an AWS EC2 key-pair and saves the private key to disk. It overwrites “key_path” file with the newly created key.

Source

pub async fn delete_key_pair(&self, key_name: &str) -> Result<()>

Deletes the AWS EC2 key-pair.

Source

pub async fn describe_vpc(&self, vpc_id: &str) -> Result<Vpc>

Source

pub async fn describe_security_groups_by_vpc( &self, vpc_id: &str, ) -> Result<Vec<SecurityGroup>>

Source

pub async fn describe_subnets_by_vpc(&self, vpc_id: &str) -> Result<Vec<Subnet>>

Source

pub async fn describe_volumes( &self, filters: Option<Vec<Filter>>, ) -> Result<Vec<Volume>>

Describes the EBS volumes by filters. ref. https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVolumes.html

Source

pub async fn poll_volume_state( &self, ebs_volume_id: String, desired_state: VolumeState, timeout: Duration, interval: Duration, ) -> Result<Option<Volume>>

Polls the EBS volume by its state.

Source

pub async fn describe_local_volumes( &self, ebs_volume_id: Option<String>, ebs_device_name: String, local_ec2_instance_id: Option<String>, ) -> Result<Vec<Volume>>

Describes the attached volume by the volume Id and EBS device name. The “local_ec2_instance_id” is only set to bypass extra EC2 metadata service API calls. The region used for API call is inherited from the EC2 client SDK.

e.g.,

aws ec2 describe-volumes
–region ${AWS::Region}
–filters
Name=attachment.instance-id,Values=$INSTANCE_ID
Name=attachment.device,Values=/dev/xvdb
–query Volumes[].Attachments[].State
–output text

ref. https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVolumes.html ref. https://github.com/ava-labs/avalanche-ops/blob/fcbac87a219a8d3d6d3c38a1663fe1dafe78e04e/bin/avalancheup-aws/cfn-templates/asg_amd64_ubuntu.yaml#L397-L409

Source

pub async fn poll_local_volume_by_attachment_state( &self, ebs_volume_id: Option<String>, ebs_device_name: String, desired_attachment_state: VolumeAttachmentState, timeout: Duration, interval: Duration, ) -> Result<Volume>

Polls the EBS volume attachment state. For instance, the “device_name” can be either “/dev/xvdb” or “xvdb” (for the secondary volume).

Source

pub async fn fetch_tags(&self, instance_id: &str) -> Result<Vec<Tag>>

Fetches all tags for the specified instance.

“If a single piece of data must be accessible from more than one task concurrently, then it must be shared using synchronization primitives such as Arc.” ref. https://tokio.rs/tokio/tutorial/spawning

Source

pub async fn list_asg(&self, asg_name: &str) -> Result<Vec<Droplet>>

Lists instances by the Auto Scaling Groups name.

Source

pub async fn allocate_eip(&self, tags: HashMap<String, String>) -> Result<Eip>

Allocates an EIP and returns the allocation Id and the public Ip. ref. https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AllocateAddress.html

Source

pub async fn associate_eip( &self, allocation_id: &str, instance_id: &str, ) -> Result<String>

Associates the elastic Ip with an EC2 instance. ref. https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AssociateAddress.html

Source

pub async fn describe_eips_by_instance_id( &self, instance_id: &str, ) -> Result<Vec<Address>>

Describes the elastic IP addresses with the instance Id. ref. https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAddresses.html

Source

pub async fn describe_eips_by_tags( &self, tags: HashMap<String, String>, ) -> Result<Vec<Address>>

Describes the elastic IP addresses with the tags. ref. https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAddresses.html

Source

pub async fn poll_eip_by_describe_addresses( &self, association_id: &str, instance_id: &str, timeout: Duration, interval: Duration, ) -> Result<Vec<Address>>

Polls the elastic Ip for its describe address state, until the elastic Ip becomes attached to the instance. ref. https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAddresses.html

Source

pub async fn create_image( &self, instance_id: &str, image_name: &str, tags: HashMap<String, String>, ) -> Result<String>

Creates an image and returns the AMI ID.

Source

pub async fn poll_image_until_available( &self, image_id: &str, timeout: Duration, interval: Duration, ) -> Result<Image>

Polls the image until the state is “Available”.

Trait Implementations§

Source§

impl Clone for Manager

Source§

fn clone(&self) -> Manager

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Manager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,