项目作者: pyToshka

项目描述 :
Tool for discover ip addresses of nodes in cloud environments based on meta information like tags provided by the environment.
高级语言: Python
项目地址: git://github.com/pyToshka/cloud-discovery.git
创建时间: 2021-01-14T04:25:44Z
项目社区:https://github.com/pyToshka/cloud-discovery

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Cloud discovery

Tool to discover nodes in cloud environments based on meta information like tags provided by the environment.

Supported clouds:

Provider name Plugin name Description
AWS cloud_discovery_plugin Retrieving informtation about EC2 instances based on tag key
Azure cloud_discovery_plugin_azure Retrieving informtation about Azure virtual machines based on tag key
DigitalOcean cloud_discovery_plugin_do Retrieving informtation about DigitalOcean droplets based on tag key
GCE cloud_discovery_plugin_gce Retrieving informtation about Google cloud instances based on tag key
Kubernetes cloud_discovery_plugin_k8s Retrieving informtation about Kubernetes pods based on tag key
Linode cloud_discovery_plugin_linode Retrieving informtation about Linodes based on tag key
OpenStack cloud_discovery_plugin_os Retrieving informtation about OpeStack instances based on tag key or property key

Default cloud at this moment AWS.

Dependencies graph

cloud_discovery

Architecture

Cloud discovery based on Groundwork.

Groundwork is a Python based microframework for highly reusable applications and their components.
Its functionality is based on exchangeable, well-documented and well-tested plugins and patterns.

Workflow:

User run command cloud_discovery, application checking input parameters and if input parameters is not presented, shows help.

If input parameter in list, checking checking option which required and output format. If output format doesn’t present, application use default output format(plain) . If all parameters and options in place, application try connect to selected cloud and get information about vm/instance/pod. Application return information about requested data or exit with error

Instalation

From GitHub

  1. python -m pip install git+https://github.com/pyToshka/cloud-discovery.git

Local installation

  1. git clone git@github.com:pyToshka/cloud-discovery.git
  2. cd pyTerrafile
  3. pip install .

Usage

General usage:

  1. cloud_discovery
  2. Usage: cloud_discovery [OPTIONS] COMMAND [ARGS]...
  3. Options:
  4. --help Show this message and exit.
  5. Commands:
  6. aws Find AWS instances by tag key
  7. azure Find Azure vms by tag key
  8. do Find Digitalocean droplets info by tag key
  9. gce Find GCE vms by tag key
  10. k8s Find Kubernetes pods by tag key
  11. li Find Linodes info by tag key
  12. os Find OpenStack instance info by tag key

General configuration:

Almost all providers following the same configuration strategy. As general strategy was choosed system environments for many reasons. Below providers specific usage and configuration.

Provider specific usage

AWS

There are two way for configuration:

  • Use ~/.aws/config file
  • System variables

For system variables make sure you exported

AWS_ACCESS_KEY_ID - The access key for your AWS account.
AWS_SECRET_ACCESS_KEY - The secret key for your AWS account.
AWS_DEFAULT_REGION - The default AWS Region to use, for example, us-west-1 or us-west-2.

or

AWS_PROFILE - The default profile to use, if any. If no value is specified, Boto3 attempts to search the shared credentials file and the config file for the default profile.
AWS_CONFIG_FILE - The location of the config file used by Boto3. By default this value is ~/.aws/config. You only need to set this variable if you want to change this location.

Example of usage:
  1. cloud_discovery aws --help
  2. Usage: cloud_discovery aws [OPTIONS]
  3. Find AWS instances by tag key
  4. Options:
  5. -t, --tag TEXT Tag name [required]
  6. -o, --output [json|plain|table]
  7. Output format for received information
  8. -a, --attribute [name|type|state|private_ip|public_ip]
  9. Get single attribute
  10. -r, --region TEXT AWS region name. Default us-east-1
  11. --help Show this message and exit.

Below example how to get all instances with tag name project

  1. cloud_discovery aws -t project

By default output is plain

  1. name: test-vm
  2. type: t3.large
  3. state: running
  4. private_ip: 127.0.0.1
  5. public_ip: 8.8.8.8
  6. ------

Json

Command cloud_discovery aws -t project -o json

Output:

  1. [
  2. {
  3. "name": "test-vm",
  4. "private_ip": "127.0.0.1",
  5. "public_ip": "8.8.8.8",
  6. "state": "running",
  7. "type": "t3.large"
  8. }
  9. ]

Table

Command cloud_discovery aws -t project -o table

Output:

  1. name | type | state | private_ip | public_ip
  2. --------------------------- | -------- | ------- | ------------ | --------------
  3. test-vm | t3.large | running | 127.0.0.1 | 8.8.8.8

As one of future cloud_discovery can return elements as string, at this moment tool supports only

  • name
  • type
  • state
  • private_ip
  • public_ip
Example:
  1. cloud_discovery aws -t project -o table -a private_ip
  2. 127.0.0.1

Azure

System environments:

AZURE_SUBSCRIPTION_ID - The Azure subscription id
AZURE_CLIENT_ID - the service principal’s client ID
AZURE_CLIENT_SECRET - one of the service principal’s client secrets
AZURE_TENANT_ID - ID of the service principal’s tenant. Also called its ‘directory’ ID.

Example:

  1. export AZURE_SUBSCRIPTION_ID="aa11bb33-cc77-dd88-ee99-0918273645aa"
  2. export AZURE_TENANT_ID="00112233-7777-8888-9999-aabbccddeeff"
  3. export AZURE_CLIENT_ID="12345678-1111-2222-3333-1234567890ab"
  4. export AZURE_CLIENT_SECRET="abcdef00-4444-5555-6666-1234567890ab"
Example of usage:
  1. cloud_discovery azure --help
  2. Usage: cloud_discovery azure [OPTIONS]
  3. Find Azure vms by tag key
  4. Options:
  5. -t, --tag TEXT Tag name [required]
  6. -o, --output [json|plain|table]
  7. Output format for received information
  8. -a, --attribute [name|type|state|private_ip|public_ip]
  9. Get single attribute
  10. -r, --resource_group TEXT Azure resource group name
  11. --help Show this message and exit.

Output format the same as for AWS

Google cloud engine

Configuration:

Befor starting make sure Cloud SDK installed and configured.

How to install and configure Cloud SDK

Setup system environment GOOGLE_APPLICATION_CREDENTIALS with Your authentication credentials

Example:
  1. export GOOGLE_APPLICATION_CREDENTIALS="/tmp/google.json"
Example of usage:
  1. cloud_discovery gce --help
  2. Usage: cloud_discovery gce [OPTIONS]
  3. Find GCE vms by tag key
  4. Options:
  5. -t, --tag TEXT Tag name [required]
  6. -o, --output [json|plain|table]
  7. Output format for received information
  8. -a, --attribute [name|type|state|private_ip|public_ip]
  9. Get single attribute
  10. -r, --region TEXT Zone name for example us-central1-a
  11. [required]
  12. -p, --project TEXT Project name [required]
  13. --help Show this message and exit.

Output format the same as for AWS

DigitalOcean

Configuration:

Make sure you exported DIGITALOCEAN_ACCESS_TOKEN as system variable

Example:
  1. export DIGITALOCEAN_ACCESS_TOKEN="dddd-dd-dddd"
Example of usage:
  1. cloud_discovery do --help
  2. Usage: cloud_discovery do [OPTIONS]
  3. Find Digitalocean droplets info by tag key
  4. Options:
  5. -t, --tag TEXT Tag name [required]
  6. -o, --output [json|plain|table]
  7. Output format for received information
  8. -a, --attribute [name|type|state|private_ip|public_ip|ipv6_address]
  9. Get single attribute

Output the same as for AWS

Kubernetes

Configuration:

Kubernetes provider use dynamic kubernetes client library. Before start you should be connected to Kubernetes cluster via kubectl, cloud_discovery will use current cluster and context

Example of usage:
  1. cloud_discovery k8s --help
  2. Usage: cloud_discovery k8s [OPTIONS]
  3. Find Kubernetes pods by tag key
  4. Options:
  5. -l, --label TEXT Pods label [required]
  6. -o, --output [json|plain|table]
  7. Output format for received information
  8. -a, --attribute [name|namespace|state|private_ip|public_ip]
  9. Get single attribute
  10. -t, --top Show pods statistic
  11. -s, --sort [cpu|memory] Sort by value
  12. -m, --limit INTEGER Number of pods in top table
  13. --help Show this message and exit.

Output fields

  • name - Kubernetes pod name
  • namespace - Kubernetes namespace name
  • state - Pod current status
  • private_ip - Pod private ip
  • public_ip - Not public ip really. Kubernetes ingress hostname

Top like output per pod. You can get/sort and limit statictic about memory and cpu usage in realtime per pod.

Example of running

  1. cloud_discovery k8s -l k8s-app=kube-proxy -t -s memory --limit 3

It means getting memory usage for application with label k8s-app=kube-proxy sorted by memory usage and show me top 3 pod

Output:

k8s_top

Linode

Configuration:

Make sure you exported LINODE_ACCESS_TOKEN as system variable

Example of usage:
  1. cloud_discovery li --help
  2. Usage: cloud_discovery li [OPTIONS]
  3. Find Linodes info by tag key
  4. Options:
  5. -t, --tag TEXT Tag name [required]
  6. -o, --output [json|plain|table]
  7. Output format for received information
  8. -a, --attribute [name|type|state|private_ip|public_ip|ipv6_address]
  9. Get single attribute
  10. --help Show this message and exit.

Output the same as for AWS

OpenStack

Configuration:

Make sure you have next system environments:

OS_AUTH_URL - The Identity authentication URL.

OS_USERNAME - The Username to login with

OS_PASSWORD - The Password to login with

OS_PROJECT_ID - The ID of the Tenant (Identity v2) or Project (Identity v3) to login with

OS_USER_DOMAIN_NAME - The domain name where the user is located.

OS_INTERFACE -OpenStack interface type

OS_REGION_NAME - The region of the OpenStack cloud to use

All variables could be exported from OpenStack rc file

Example of usage:
  1. cloud_discovery os --help
  2. Usage: cloud_discovery os [OPTIONS]
  3. Find OpenStack instance info by tag key
  4. Options:
  5. -t, --tag TEXT Tag or property name [required]
  6. -o, --output [json|plain|table]
  7. Output format for received information
  8. -a, --attribute [name|type|state|private_ip|public_ip]
  9. Output format for received information
  10. --help Show this message and exit.

cloud_discovery try to get information based on tag or properties