Skip to main content

No project description provided

Project description

Made with pop, a Python implementation of Plugin Oriented Programming Made with Python

About

Spotinst Provider Idem plugin

What is POP?

This project is built with pop, a Python-based implementation of Plugin Oriented Programming (POP). POP seeks to bring together concepts and wisdom from the history of computing in new ways to solve modern computing problems.

For more information:

Getting Started

Prerequisites

  • Python 3.7+

  • git (if installing from source, or contributing to the project)

Installation

If wanting to use idem-spotinst, you can do so from source.

Install from source

# clone repo
git clone git@<your-project-path>/idem-spotinst.git
cd idem-spotinst

# Setup venv
python3 -m venv .venv
source .venv/bin/activate
pip install -e .

Usage

Credentials Setup

After installation, the spotinst Idem execution and state modules will be accessible to the pop hub. In order to use them, we need to set up our credentials.

For more information:

Create a new file called credentials.yaml and populate it with credentials. The default profile will be picked up automatically by idem.

There are multiple authentication backends for idem-spotinst which each have their own unique set of parameters. The following examples show the parameters that can be used to define credential profiles.

credentials.yaml:

spotinst:
  default:
    account_id: act-11c833de
    token: b5460afe3c29a30c28abd54d190d1aa923587574321e75925cfc8268b54b4562

Next step is to encrypt the credentials file, and add the encryption key and encrypted file path to the ENVIRONMENT.

Encrypt the credential file:

Idem encrypt credentials.yaml

This will generate a credentials.yaml.fernet file and a command line output token:

-AXFSEFSSEjsfdG_lb333kVhCVSCDyOFH4eABCDEFNwI=

Add these to your environment:

export ACCT_KEY="-AXFSEFSSEjsfdG_lb333kVhCVSCDyOFH4eABCDEFNwI="
export ACCT_FILE=$PWD/credentials.yaml.fernet

You are ready to use idem-spotinst!!!

STATES

Idem states are used to make sure resources are in a desired state. The desired state of a resource can be specified in sls file. In Idem-spotinst, three states are supported: present, absent, describe

present state

present state makes sure a resource exists in a desired state. If a resource does not exist, running present will create the resource on the provider. If a resource exists, running present will update the resource on the provider. (Only the values that the spotinst REST api supports can be updated.)

absent state

absent state makes sure a resource does not exist. If a resource exits, running absent will delete the resource. If a resource does not exist, running absent is a no-operation.

describe state

describe state lists all the current resources of the same resource type under the spotinst account id specified in the credential profile.

States can be accessed by their relative location in idem-spotinst/idem_spotinst/states. For example, in the state sls yaml file below, spotinst launch specification state can be created with the present function.

my_resource_launch_spec_state.sls:

my_resource_launch_spec:
    spotinst.ocean.aws.launch_spec.present:
      - name: my_resource_launch_spec
      - taints:
        - effect: NoSchedule
          key: taint1
          value: taint-value-1
      - tags:
        - tagKey: Env
          tagValue: test
      - subnet_ids:
        - subnet-06747be60363933d9
        - subnet-03b6d0dfc57e1gbd6
      - security_group_ids:
        - sg-08dcdf4874a2f5g04
        - sg-0844f76b69f16b8b8
      - ocean_id: o-b78b1e79
      - labels:
        - key: tag1
          value: value1
        - key: tag2
          value: value2
      - instance_types:
        - t2.micro
      - image_id: ami-0c02fb55956c7d318

The state sls file can be executed with:

idem state $PWD/my_resource_launch_spec_state.sls

The resource parameters in an sls yaml file follow the exact structure as what’s in the Spotinst REST api doc . URI Parameters should be specified in snake case with “- “ in front. All parameters of the api request body should be specified in exactly the same way as what’s in the spotinst REST api.

Current Supported Resources states

ocean_aws

k8s_cluser

launch_spec

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

idem-spotinst-0.1.0.tar.gz (21.3 kB view hashes)

Uploaded Source

Built Distribution

idem_spotinst-0.1.0-py3-none-any.whl (23.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page