Cloud Infrastructure
This module provides classes which form the backbone of nOps SDK’s cloud pricing and dependency functionality.
See, for example, nops_sdk.pricing.compute_price_change()
for inspiration on how they are used.
Cloud Operation
- class nops_sdk.cloud_infrastructure.cloud_operation.CloudOperation(type, created_resource=None, deleted_resource=None)
Bases:
object
An operation in AWS (such as create EC2 with Terraform)
- Parameters
type (nops_sdk.cloud_infrastructure.enums.CloudOperationType) – an instance of CloudOperationType specifying the action taken
created_resource (Optional[nops_sdk.cloud_infrastructure._resource.Resource]) – the AWS resource which is created with this operation
deleted_resource (Optional[nops_sdk.cloud_infrastructure._resource.Resource]) – the AWS resource which is deleted with this operation
_cost_effect – cost effect of the action on the AWS bill
_report – a formatted report of the cost effect of this operation
- Return type
None
- __init__(type, created_resource=None, deleted_resource=None)
- Parameters
type (nops_sdk.cloud_infrastructure.enums.CloudOperationType) –
created_resource (Optional[nops_sdk.cloud_infrastructure._resource.Resource]) –
deleted_resource (Optional[nops_sdk.cloud_infrastructure._resource.Resource]) –
- Return type
None
- compute_cost_effect(period)
Compute the price effect of the operation for the provided period.
- Parameters
period (nops_sdk.cloud_infrastructure.enums.Periodicity) – length of the period
- Returns
the cost effect of the operation in the given period
- Return type
cost_change
- Raises
- property cost_effect
- created_resource: Optional[nops_sdk.cloud_infrastructure._resource.Resource] = None
- deleted_resource: Optional[nops_sdk.cloud_infrastructure._resource.Resource] = None
- classmethod from_raw_input(spec_item)
Build a CloudOperation from raw user input (e.g. terraform changeset input).
- Parameters
spec_item (dict[str, str]) –
- property report
- resources()
Produce a {domain_id: Resource} dict of this operation’s resources.
- Return type
dict
Enums
- class nops_sdk.cloud_infrastructure.enums.AWSProductFamily(value)
Bases:
str
,enum.Enum
Supported AWS producted families
- EC2 = 'ec2'
- EKS = 'aws_eks_cluster'
- EKS_NODE_GROUP = 'aws_eks_node_group'
- RDS = 'rds'
- property resource_class: Resource
- class nops_sdk.cloud_infrastructure.enums.AWSRegion(value)
Bases:
str
,enum.Enum
AWS regions
- AF_SOUTH_1 = 'af-south-1'
- AP_EAST_1 = 'ap-east-1'
- AP_NORTHEAST_1 = 'ap-northeast-1'
- AP_NORTHEAST_2 = 'ap-northeast-2'
- AP_NORTHEAST_3 = 'ap-northeast-3'
- AP_SOUTHEAST_1 = 'ap-southeast-1'
- AP_SOUTHEAST_2 = 'ap-southeast-2'
- AP_SOUTHEAST_3 = 'ap-southeast-3'
- AP_SOUTH_1 = 'ap-south-1'
- CA_CENTRAL_1 = 'ca-central-1'
- EU_CENTRAL_1 = 'eu-central-1'
- EU_NORTH_1 = 'eu-north-1'
- EU_SOUTH_1 = 'eu-south-1'
- EU_WEST_1 = 'eu-west-1'
- EU_WEST_2 = 'eu-west-2'
- EU_WEST_3 = 'eu-west-3'
- ME_SOUTH_1 = 'me-south-1'
- SA_EAST_1 = 'sa-east-1'
- US_EAST_1 = 'us-east-1'
- US_EAST_2 = 'us-east-2'
- US_WEST_1 = 'us-west-1'
- US_WEST_2 = 'us-west-2'
Instance
- class nops_sdk.cloud_infrastructure.instance.Instance(aws_id='', instance_type='', unit_of_price=<factory>, price_per_unit=<factory>, ami=None, related_resources=<factory>)
Bases:
nops_sdk.cloud_infrastructure._resource.Resource
Designates an AWS EC2 instance
- Parameters
instance_type (Optional[str]) – an identifier of resource instance (e.g. t2.micro)
unit_of_price (Optional[str]) – the unit of measurement for price (e.g. Hr in $1/Hr)
price_per_unit (Optional[decimal.Decimal]) – price of the resource for the specified unit
ami (Optional[nops_sdk.cloud_infrastructure.ami.Ami]) – the AWS AMI associated with this image
aws_id (Optional[str]) –
related_resources (Optional[dict[str, nops_sdk.cloud_infrastructure._resource.Resource]]) –
- Return type
None
- __init__(aws_id='', instance_type='', unit_of_price=<factory>, price_per_unit=<factory>, ami=None, related_resources=<factory>)
- Parameters
aws_id (Optional[str]) –
instance_type (Optional[str]) –
unit_of_price (Optional[str]) –
price_per_unit (Optional[decimal.Decimal]) –
ami (Optional[nops_sdk.cloud_infrastructure.ami.Ami]) –
related_resources (Optional[dict[str, nops_sdk.cloud_infrastructure._resource.Resource]]) –
- Return type
None
- ami: Optional[nops_sdk.cloud_infrastructure.ami.Ami] = None
- classmethod from_raw_input(spec_item)
Build a class instance from raw input.
- Parameters
spec_item (dict[str, str]) –
- Returns
instance
- Return type
- instance_type: Optional[str] = ''
- price_per_unit: Optional[decimal.Decimal]
- to_db_query(region)
Export parameters in the format of a Db query
- Parameters
- Return type
dict[str, str]
- unit_of_price: Optional[str]
RDS Instance
- class nops_sdk.cloud_infrastructure.rds_instance.RDSInstance(aws_id='', instance_class='', engine='', multi_az=False, license='general-public-license', unit_of_price='', price_per_unit=Decimal('0'), usage_operation='', related_resources=<factory>)
Bases:
nops_sdk.cloud_infrastructure._resource.Resource
Designates an AWS RDS instance
- Parameters
instance_class (Optional[str]) – an identifier of resource instance (e.g. db.t2.micro)
unit_of_price (Optional[str]) – the unit of measurement for price (e.g. Hr in $1/Hr)
price_per_unit (Optional[decimal.Decimal]) – price of the resource for the specified unit
aws_id (Optional[str]) –
engine (Optional[str]) –
multi_az (Optional[bool]) –
license (Optional[Literal['general-public-license', 'bring-your-own-license', 'amazon-license']]) –
usage_operation (Optional[str]) –
related_resources (Optional[dict[str, nops_sdk.cloud_infrastructure._resource.Resource]]) –
- Return type
None
- __init__(aws_id='', instance_class='', engine='', multi_az=False, license='general-public-license', unit_of_price='', price_per_unit=Decimal('0'), usage_operation='', related_resources=<factory>)
- Parameters
aws_id (Optional[str]) –
instance_class (Optional[str]) –
engine (Optional[str]) –
multi_az (Optional[bool]) –
license (Optional[Literal['general-public-license', 'bring-your-own-license', 'amazon-license']]) –
unit_of_price (Optional[str]) –
price_per_unit (Optional[decimal.Decimal]) –
usage_operation (Optional[str]) –
related_resources (Optional[dict[str, nops_sdk.cloud_infrastructure._resource.Resource]]) –
- Return type
None
- engine: Optional[str] = ''
- classmethod from_raw_input(spec_item)
Build a class instance from raw input.
- Parameters
spec_item (dict[str, typing.Any]) –
- Returns
rds_instance
- Return type
- instance_class: Optional[str] = ''
- license: Optional[Literal['general-public-license', 'bring-your-own-license', 'amazon-license']] = 'general-public-license'
- multi_az: Optional[bool] = False
- property multi_az_str
- price_per_unit: Optional[decimal.Decimal] = Decimal('0')
- to_db_query(region)
Export parameters in the format of a Db query
- Parameters
- Return type
dict[str, typing.Any]
- unit_of_price: Optional[str] = ''
- usage_operation: Optional[str] = ''
EKS Cluster
- class nops_sdk.cloud_infrastructure.eks_cluster.EKSCluster(aws_id='', name='')
Bases:
nops_sdk.cloud_infrastructure._resource.Resource
Designates an AWS EKS cluster
- Parameters
name (str) – name of the AWS EKS cluster
price_per_unit – price of the resource for the specified unit
aws_id (Optional[str]) –
- Return type
None
price_per_unit: Optional[Decimal] = Decimal(“0”)
- __init__(aws_id='', name='')
- Parameters
aws_id (Optional[str]) –
name (str) –
- Return type
None
- classmethod from_raw_input(spec_item)
Build a class instance from raw input.
- Parameters
spec_item (dict[str, typing.Any]) –
- Returns
eks_cluster
- Return type
- name: str = ''
- to_db_query(region)
Export parameters in the format of a Db query
- Parameters
- Return type
dict[str, typing.Any]
- class nops_sdk.cloud_infrastructure.eks_cluster.EKSNodeGroup(aws_id='', name='', cluster_name='', min_size=0, max_size=0, desired_size=0, instance_types=<factory>, _price_per_unit=None)
Bases:
nops_sdk.cloud_infrastructure._resource.Resource
Designates an AWS EKS Node Group
- Parameters
name (str) – name of the EKS Node group
cluster_name (str) – name of the associated EKS cluster
min_size (int) – minimum number of instances required in the node
max_size (int) – maximum number of instances required in the node
desired_size (int) – target number of instances required in the node
instances_types – type of instances (e.g. m6i.large)
aws_id (Optional[str]) –
instance_types (list[str]) –
_price_per_unit (Optional[decimal.Decimal]) –
- Return type
None
- __init__(aws_id='', name='', cluster_name='', min_size=0, max_size=0, desired_size=0, instance_types=<factory>, _price_per_unit=None)
- Parameters
aws_id (Optional[str]) –
name (str) –
cluster_name (str) –
min_size (int) –
max_size (int) –
desired_size (int) –
instance_types (list[str]) –
_price_per_unit (Optional[decimal.Decimal]) –
- Return type
None
- cluster_name: str = ''
- desired_size: int = 0
- classmethod from_raw_input(spec_item)
Build a class instance from raw input.
- Parameters
spec_item (dict[str, typing.Any]) –
- Returns
an instance of EKSNodeGroup
- Return type
- instance_types: list[str]
- property max_price
- max_size: int = 0
- property min_price
- min_size: int = 0
- name: str = ''
- property price_per_unit
Price_per_unit is understood as the price of this node group assuming a desired number of instances are running.
- to_db_query(region)
Export parameters in the format of a Db query
- Parameters
- Return type
dict[str, str]