Skip to content

Commit

Permalink
Added ResourceRequirements, VolumeAttachments models in AWS EG (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragsharma-123 authored Oct 21, 2024
1 parent d820b59 commit a939947
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.16.0] - 2024-10-21
### Added
- Import EC2 instance API support added in the AWS Elastigroup Client.
- Added `VolumeAttachments` and `ResourceRequirements` models for AWS Elastigroup.

## [3.15.1] - 2024-09-19
### Fixed
- Create/Update rightsizing rule APIs fixed for optional parameters.
Expand Down
34 changes: 29 additions & 5 deletions docs/clients/elastigroup/elastigroup_aws_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ ElastigroupAwsClient.beanstalk_import(region,
env_name=None)
```

Import beanstalk attributes into JSON. Either env_id or env_name is required, both cannot be null
Import beanstalk attributes into JSON. Either env_id or env_name is
required, both cannot be null

__Arguments__

Expand Down Expand Up @@ -608,13 +609,35 @@ __Returns__

`(Object)`: Elastigroup API response

<h2 id="spotinst_sdk2.clients.elastigroup.ElastigroupAwsClient.import_instance">import_instance</h2>

```python
ElastigroupAwsClient.import_instance(region, instance_id,
instance: ImportInstanceConfig)
```

Import an EC2 instance into a new Elastigroup

__Arguments__

- __region (String)__: Instance Region
- __instance_id (String)__: Instance ID
- __instance (ImportInstanceConfig)__: Import Configuration

__Returns__

`(Object)`: Elastigroup API response

<h2 id="spotinst_sdk2.clients.elastigroup.ElastigroupAwsClient.import_asg">import_asg</h2>

```python
ElastigroupAwsClient.import_asg(region, asg_name, asg, dry_run=None)
ElastigroupAwsClient.import_asg(region,
asg_name,
asg: ASG,
dry_run=None)
```

import asg attributes as JSON
Create a new Elastigroup using the configuration of an existing Autoscaling group

__Arguments__

Expand Down Expand Up @@ -886,8 +909,9 @@ __Arguments__
- __group_id(String)__: Elastigroup ID
- __to_date (String)__: to date
- __from_date (String)__: to date
- __severity(String) (Optional)__: Log level severity
- __resource_id(String) (Optional)__: Filter log extracted entires related to a specific resource id
- __severity (String) (Optional)__: Log level severity
- __resource_id (String) (Optional)__: Filter log extracted entires related to a
specific resource id
- __limit(String) (Optional)__: Maximum number of lines to extract in a response

__Returns__
Expand Down
89 changes: 86 additions & 3 deletions docs/models/elastigroup/aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ __Arguments__
Strategy(
self,
availability_vs_cost='d3043820717d74d9a17694c176d39733',
consider_o_d_pricing='d3043820717d74d9a17694c176d39733',
risk='d3043820717d74d9a17694c176d39733',
utilize_commitments='d3043820717d74d9a17694c176d39733',
utilize_reserved_instances='d3043820717d74d9a17694c176d39733',
fallback_to_od='d3043820717d74d9a17694c176d39733',
max_replacements_percentage='d3043820717d74d9a17694c176d39733',
on_demand_count='d3043820717d74d9a17694c176d39733',
draining_timeout='d3043820717d74d9a17694c176d39733',
spin_up_time='d3043820717d74d9a17694c176d39733',
Expand All @@ -54,10 +56,12 @@ Strategy(
__Arguments__

- __availability_vs_cost__: str
- __consider_o_d_pricing__: bool
- __risk__: int
- __utilize_commitments__: bool
- __utilize_reserved_instances__: bool
- __fallback_to_od__: bool
- __max_replacements_percentage__: int
- __on_demand_count__: int
- __draining_timeout__: int
- __spin_up_time__: int
Expand All @@ -67,6 +71,7 @@ __Arguments__
- __persistence__: Persistence
- __revert_to_spot__: RevertToSpot
- __restrict_single_az__: bool
- __immediate_o_d_recover_threshold__: int

<h2 id="spotinst_sdk2.models.elastigroup.aws.Signal">Signal</h2>

Expand Down Expand Up @@ -941,7 +946,8 @@ Compute(self,
elastic_ips='d3043820717d74d9a17694c176d39733',
private_ips='d3043820717d74d9a17694c176d39733',
subnet_ids='d3043820717d74d9a17694c176d39733',
preferred_availability_zones='d3043820717d74d9a17694c176d39733')
preferred_availability_zones='d3043820717d74d9a17694c176d39733',
volume_attachments='d3043820717d74d9a17694c176d39733')
```

__Arguments__
Expand All @@ -954,6 +960,7 @@ __Arguments__
- __private_ips__: list[str]
- __subnet_ids__: list[str]
- __preferred_availability_zones__: list[str]
- __volume_attachments__: VolumeAttachments

<h2 id="spotinst_sdk2.models.elastigroup.aws.AvailabilityZone">AvailabilityZone</h2>

Expand Down Expand Up @@ -981,7 +988,8 @@ InstanceTypes(self,
on_demand_types='d3043820717d74d9a17694c176d39733',
spot='d3043820717d74d9a17694c176d39733',
weights='d3043820717d74d9a17694c176d39733',
preferred_spot='d3043820717d74d9a17694c176d39733')
preferred_spot='d3043820717d74d9a17694c176d39733',
resource_requirements='d3043820717d74d9a17694c176d39733')
```

__Arguments__
Expand All @@ -991,6 +999,29 @@ __Arguments__
- __spot__: list[str]
- __weights__: list[Weight]
- __preferred_spot__: list[str]
- __resource_requirements__: ResourceRequirements

<h2 id="spotinst_sdk2.models.elastigroup.aws.ResourceRequirements">ResourceRequirements</h2>

```python
ResourceRequirements(
self,
excluded_instance_families='d3043820717d74d9a17694c176d39733',
excluded_instance_generations='d3043820717d74d9a17694c176d39733',
excluded_instance_types='d3043820717d74d9a17694c176d39733',
required_v_cpu='d3043820717d74d9a17694c176d39733',
required_memory='d3043820717d74d9a17694c176d39733',
required_gpu='d3043820717d74d9a17694c176d39733')
```

__Arguments__

- __excluded_instance_families__: list[str]
- __excluded_instance_generations__: list[str]
- __excluded_instance_types__: list[str]
- __required_v_cpu__: RequiredMemoryVcpuGpu
- __required_memory__: RequiredMemoryVcpuGpu
- __required_gpu__: RequiredMemoryVcpuGpu

<h2 id="spotinst_sdk2.models.elastigroup.aws.Weight">Weight</h2>

Expand All @@ -1005,6 +1036,19 @@ __Arguments__
- __instance_type__: str
- __weighted_capacity__: int

<h2 id="spotinst_sdk2.models.elastigroup.aws.RequiredMemoryVcpuGpu">RequiredMemoryVcpuGpu</h2>

```python
RequiredMemoryVcpuGpu(self,
minimum='d3043820717d74d9a17694c176d39733',
maximum='d3043820717d74d9a17694c176d39733')
```

__Arguments__

- __minimum__: int
- __maximum__: int

<h2 id="spotinst_sdk2.models.elastigroup.aws.TagSpecification">TagSpecification</h2>

```python
Expand Down Expand Up @@ -1292,6 +1336,29 @@ __Arguments__
- __http_tokens__: str
- __instance_metadata_tags__: str

<h2 id="spotinst_sdk2.models.elastigroup.aws.VolumeAttachments">VolumeAttachments</h2>

```python
VolumeAttachments(self, volumes='d3043820717d74d9a17694c176d39733')
```

__Arguments__

- __volumes__: list[Volume]

<h2 id="spotinst_sdk2.models.elastigroup.aws.Volume">Volume</h2>

```python
Volume(self,
device_name='d3043820717d74d9a17694c176d39733',
volume_id='d3043820717d74d9a17694c176d39733')
```

__Arguments__

- __device_name__: str
- __volume_id__: str

<h2 id="spotinst_sdk2.models.elastigroup.aws.Roll">Roll</h2>

```python
Expand Down Expand Up @@ -1392,12 +1459,28 @@ __Arguments__
ASG(self,
product='d3043820717d74d9a17694c176d39733',
spot_instance_types='d3043820717d74d9a17694c176d39733',
name='d3043820717d74d9a17694c176d39733')
name='d3043820717d74d9a17694c176d39733',
availability_vs_cost='d3043820717d74d9a17694c176d39733')
```

__Arguments__

- __product__: str
- __spot_instance_types__: List[str]
- __name__: str
- __availability_vs_cost__: str

<h2 id="spotinst_sdk2.models.elastigroup.aws.asg.ImportInstanceConfig">ImportInstanceConfig</h2>

```python
ImportInstanceConfig(
self,
spot_instance_types='d3043820717d74d9a17694c176d39733',
name='d3043820717d74d9a17694c176d39733')
```

__Arguments__

- __spot_instance_types__: List[str]
- __name__: str

Expand Down
51 changes: 45 additions & 6 deletions spotinst_sdk2/clients/elastigroup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import spotinst_sdk2.models.elastigroup.aws.stateful as aws_stateful
import spotinst_sdk2.models.elastigroup.aws.deployment as aws_deployment
import spotinst_sdk2.models.elastigroup.aws.deployment_action as aws_deployment_action
import spotinst_sdk2.models.elastigroup.aws.asg as aws_asg
import spotinst_sdk2.models.elastigroup.aws.asg as aws_import
# endregion

# region GCP imports
Expand Down Expand Up @@ -931,9 +931,48 @@ def beanstalk_reimport(self, group_id):

return ret_val

def import_asg(self, region, asg_name, asg, dry_run=None):
def import_instance(self, region, instance_id, instance: aws_import.ImportInstanceConfig):
"""
import asg attributes as JSON
Import an EC2 instance into a new Elastigroup
# Arguments
region (String): Instance Region
instance_id (String): Instance ID
instance (ImportInstanceConfig): Import Configuration
# Returns
(Object): Elastigroup API response
"""
query_params = dict(
region=region, instanceId=instance_id)

request = aws_import.ImportInstanceRequest(instance)

excluded_group_dict = self.exclude_missing(
json.loads(request.toJSON()))

formatted_group_dict = self.convert_json(
excluded_group_dict, self.underscore_to_camel)

body_json = json.dumps(formatted_group_dict)

response = self.send_post(
body=body_json,
url=self.__base_elastigroup_url +
"/instance/import",
query_params=query_params,
entity_name='import instance')

formatted_response = self.convert_json(
response, self.camel_to_underscore)

ret_val = formatted_response["response"]["items"][0]

return ret_val

def import_asg(self, region, asg_name, asg: aws_import.ASG, dry_run=None):
"""
Create a new Elastigroup using the configuration of an existing Autoscaling group
# Arguments
region (String): ASG region
Expand All @@ -947,7 +986,7 @@ def import_asg(self, region, asg_name, asg, dry_run=None):
query_params = dict(
region=region, autoScalingGroupName=asg_name, dryRun=dry_run)

asg = aws_asg.ImportASGRequest(asg)
asg = aws_import.ImportASGRequest(asg)

excluded_group_dict = self.exclude_missing(json.loads(asg.toJSON()))

Expand Down Expand Up @@ -1343,8 +1382,8 @@ def get_elastilog(self, group_id, from_date, to_date, severity=None, resource_id
group_id(String): Elastigroup ID
to_date (String): to date
from_date (String): to date
severity(String) (Optional): Log level severity
resource_id(String) (Optional): Filter log extracted entires related to a
severity (String) (Optional): Log level severity
resource_id (String) (Optional): Filter log extracted entires related to a
specific resource id
limit(String) (Optional): Maximum number of lines to extract in a response
Expand Down
Loading

0 comments on commit a939947

Please sign in to comment.