Skip to content

Instantly share code, notes, and snippets.

@Jammink2
Last active May 12, 2019 08:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Jammink2/e9b36ff0c9278e223a4404f473a676dd to your computer and use it in GitHub Desktop.
Contains commands for "Command line magic with AVN CLI". Saved as an .sh to enable syntax highlighting.
#Contains commands for "Command line magic with AVN CLI".
#Saved as an .sh to enable syntax highlighting.
#jammink@aiven.io
#login a user
avn user login user@aiven.io
## get help with user admin
avn user -h
#list all available users
avn user info
#logout
avn logout
#list all available services on Aiven
avn service types
#list all available clouds
avn cloud list
#list all available clouds in the United States
avn cloud list | grep United
#list the last five clouds, by region alphabetically, in US region
avn cloud list | grep United | tail -5
#list the first three clouds in the US region
avn cloud list | grep United | head -5
#list the first 20 clouds in the US region
avn cloud list | grep United | head -20
# list all clouds available in "California" region. Note: writes a file (ca_clouds)
avn cloud list | grep -E "California" > ca_clouds && cat ca_clouds
# exclude all clouds in Finland and California. Note: writes to a file (not_ca_not_fi_clouds)
avn cloud list | grep -Ev "California|Finland" > not_ca_not_fi_clouds && cat not_ca_not_fi_clouds
# count all clouds in a given region
avn cloud list | grep -E "California" > ca_clouds && wc -l ca_clouds
# list clouds in successive alphabetical order by 3 specified regions
regions=('africa' 'australia' 'europe')
for r in "${regions[@]}"
do
avn cloud list | grep $r
done
# list all clouds filtered by a specific cloud provider (in this case, aws-) within 2 regions
clear && avn cloud list | grep -E 'europe|north america' | grep 'aws-'
# count the total number of available Aiven clouds
avn cloud list | grep -Ev 'CLOUD_DESCRIPTION|=' > clouds_adjusted && wc -l clouds_adjusted
# list all clouds, sorted by alphabetically by provider
providers=('aws-' 'azure-' 'do-' 'google' 'packet')
for p in "${providers[@]}"
do
avn cloud list | grep $p
done
# List all available plans, given the cloud
avn service plans --cloud do-sfo
# List all available hobbyist plans, given the cloud
avn service plans --cloud do-sfo | grep -E 'hobbyist'
# List all available kafka plans, given the cloud
avn service plans --cloud do-sfo | grep -E 'kafka:'
# List all available postgres and kafka plans within a specified cloud, filtered by CPU constraints
clear && avn service plans --cloud do-sfo | grep -E 'pg:|kafka:' | grep -E '8 CPU|16 CPU'
# count the number of available plans in a specific cloud
avn service plans --cloud do-sfo | grep -E 'cassandra:|elasticsearch:|grafana:|influxdb:|kafka:|mysql:|pg:|redis:' > plans_adjusted && wc -l plans_adjusted
# count all plans on a specific cloud with costs < $10/hr
avn service plans --cloud do-sfo | grep -Ev '\$\d\d.\d{3}/h' | grep -E 'cassandra:|elasticsearch:|grafana:|influxdb:|kafka:|mysql:|pg:|redis:' > cheap_plans_adjusted && wc -l cheap_plans_adjusted
# make a nicely formatted text file of < $10/hr plans on a specific cloud and display it
avn service plans --cloud do-sfo | grep -Ev '\$\d\d.\d{3}/h' > cheap_plans && cat cheap_plans
#list all plans on a specific cloud with costs < $10/hr
clear && avn service plans --cloud do-sfo | grep -Ev '\$\d\d.\d{3}/h' | more
#list all plans on a specific cloud with costs > $10/hr
clear && avn service plans --cloud do-sfo | grep -E '\$\d\d.\d{3}/h'
#create an Elasticsearch service with hobbyist plan
avn service create myes -t elasticsearch --plan hobbyist
#create a cassandra instance with startup-4 Plan
avn service create mycass -t cassandra --plan startup-4
#create a kafka instance with next higher tier
avn service create mykafka -t kafka --plan business-4
#roll out multiple service instances on multiple tiers
avn service create mycass -t cassandra --plan startup-4 && avn service create mykafka -t kafka --plan business-4
#upgrade an existing service to a higher tier
avn service update mycass --plan startup-8
#upgrade an existing service to a higher tier AND move it to another cloud region
avn service update mycass --plan startup-8 --cloud aws-us-west-1
#list all of your available aiven services
avn service list
# poweron multiple services
avn service update myes1 --power-on && avn service update myes2 --power-on
#list all services currently running
avn service list | grep POWERON
#list all services currently switched off
avn service list | grep POWEROFF
# get the timestamps (for each service, CREATE_TIME and UPDATE_TIME) for your recently switched off services
avn service list | grep POWEROFF | grep -Eo '\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(.\d{6})?((\+\d\d:\d\d)|Z)'
# get the latest timestamps for currently running services
avn service list | grep RUNNING | grep -Eo '\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(.\d{6})?((\+\d\d:\d\d)|Z)'
# get the latest timestamps for currently rebuilding services
avn service list | grep REBUILDING | grep -Eo '\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(.\d{6})?((\+\d\d:\d\d)|Z)'
#create an Elasticsearch service on your default cloud, hobbyist plan
avn service create myes -t elasticsearch --plan hobbyist
# power off your service and list services
avn service update myes --power-off && avn service list
# poweroff multiple service instances
services=('mycass' 'mykafka' 'myes')
for s in "${services[@]}"
do
avn service update $s --power-off
done
#terminate multiple service instances
avn service terminate mycass && avn service terminate mykafka
#show all service events in your project
avn events
## find 5 most recent events
avn events | grep -Ev 'TIME|=' | head -5
## find service maintenance events
avn events | grep -E '_maintenance'
## find service_delete events for your logged in project
avn events | grep -E '_delete'
# count the number of lines in event log
avn events | grep -Ev 'TIME|=' > events && wc -l events
#list all events related to powered on and powered off services
avn events | grep power > power_events && cat power_events
#list all events not related to powered up or down services
avn events | grep -Ev power > live_events && cat live_events
# get help
avn help
avn -h
# get help on specific function
avn card -h
avn cloud -h
avn credits -h
avn events -h
avn project -h
avn service -h
avn service create -h
#list the credit cards associated with your project
avn card list
# list all available credits in your project
avn credits list
#list all of your current projects
avn project list
#get project details, including associated credit card, billing address and country code
avn project details
# list all vpcs
avn vpc list
#### ~~~~ Aliases for popular commands ~~~ ###############
#list clouds, in order alphabetically by 3 major regions
show_my_clouds() {
clear
regions=('australia' 'europe' 'north')
for r in "${regions[@]}"
do
avn cloud list | grep $r
done }
#view plans on a specific cloud that cost < $10/hr
get_cheap_plans() {
clear && avn service plans --cloud do-sfo | grep -Ev '\$\d\d.\d{3}/h' | more
}
#to turn on a specific service
alias turnon_service='avn service update myes --power-on'
#to turn off a specific service
alias turnoff_service='avn service update myes --power-off'
#get timestamps from all services
alias get_timestamps='avn service list | grep -Eo "\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(.\d{6})?((\+\d\d:\d\d)|Z)"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment