diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index eaba5b5..9f51967 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,27 @@ # eqx +## Token +export PACKET_TOKEN=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + + +Or + + +cat $HOME/.packet-cli.json + + +{ + "token": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +} + + + +## Dependencies +apt install jq + +git clone https://github.com/packethost/packet-cli + +mkdir -p ~/bin +wget -O ~/bin/packet https://github.com/packethost/packet-cli/releases/download/0.1.1/packet-linux-amd64 +chmod +x ~/bin/packet + diff --git a/eqx-cluster-create b/eqx-cluster-create new file mode 100755 index 0000000..d6497e1 --- /dev/null +++ b/eqx-cluster-create @@ -0,0 +1,17 @@ +#!/bin/bash +# eqx-cluster-create +# +# Create a cluster of bare metal on Equinix +# +# Usage: +# eqx-cluster-create +# Example: +# eqx-cluster-create +# + +set -x + +# + +EQXRANDHOST=`dd bs=12 count=1 if=/dev/random 2>/dev/null | base64 | tr [:upper:] [:lower:] | tr -dc [:alpha:]` + diff --git a/eqx-create-org b/eqx-create-org new file mode 100755 index 0000000..a54950c --- /dev/null +++ b/eqx-create-org @@ -0,0 +1,39 @@ +#!/bin/bash +# Usage: +# eqx-create-org [name] +# Example: +# eqx-create-org fooorg +# eqx-create-org fooorg --description "barrog" --website "http://127.0.0.1" + +set -x + +packet \ + organization \ + create \ + --name "$@" + +exit + +Example: + +packet organization create -n [name] + +Usage: + packet organization create [flags] + +Flags: + -d, --description string Description of the organization + -h, --help help for create + -l, --logo string Logo URL] + -n, --name string Name of the organization + -t, --twitter string Twitter URL of the organization + -w, --website string Website URL of the organization + +Global Flags: + --config string Path to JSON or YAML configuration file + --exclude strings Comma seperated Href references to collapse in results, may be dotted three levels deep + --include strings Comma seperated Href references to expand in results, may be dotted three levels deep + -j, --json JSON output + --search string Search keyword for use in 'get' actions. Search is not supported by all resources. + -y, --yaml YAML output + diff --git a/eqx-create-project b/eqx-create-project new file mode 100755 index 0000000..c556cbb --- /dev/null +++ b/eqx-create-project @@ -0,0 +1,57 @@ +#!/bin/bash +# eqx-create-project +# Create an Equinix Project. +# If no name is given, a random string is chosen +# +# Usage: +# eqx-create-project [name] +# Example: +# eqx-create-project +# eqx-create-project fooproject + +EQXRAND=`dd bs=12 count=1 if=/dev/random 2>/dev/null | base64 | tr [:upper:] [:lower:] | tr -dc [:alpha:]` +EQXPROJECT="$1" + +if [[ $1 == "" ]] + then EQXPROJECT=$EQXRAND +fi + +packet \ + project \ + create \ + --name \ + $EQXPROJECT \ + 2>/dev/null | \ + grep -v -e "^+" -e "CREATED" | \ + cut -f 4 -d " " + + +exit + +2021/01/23 14:45:25 [DEBUG] POST https://api.equinix.com/metal/v1/projects ++--------------------------------------+--------------+----------------------+ +| ID | NAME | CREATED | ++--------------------------------------+--------------+----------------------+ +| 7ac35d0b-17be-4e76-a15a-cc68a3f3d81b | udmlbdyxsouf | 2021-01-23T21:45:26Z | ++--------------------------------------+--------------+----------------------+ + + +packet project create --name [project_name] + +Usage: + packet project create [flags] + +Flags: + -h, --help help for create + -n, --name string Name of the project + -o, --organization-id string UUID of the organization + -m, --payment-method-id string UUID of the payment method + +Global Flags: + --config string Path to JSON or YAML configuration file + --exclude strings Comma seperated Href references to collapse in results, may be dotted three levels deep + --include strings Comma seperated Href references to expand in results, may be dotted three levels deep + -j, --json JSON output + --search string Search keyword for use in 'get' actions. Search is not supported by all resources. + -y, --yaml YAML output + diff --git a/eqx-delete-project b/eqx-delete-project new file mode 100755 index 0000000..28e0047 --- /dev/null +++ b/eqx-delete-project @@ -0,0 +1,32 @@ +#!/bin/bash +# eqx-delete-project +# Delete an Equinix Project. +# +# Usage: +# eqx-delete-project [name] +# Example: +# eqx-delete-project fooproject + +#set -x + +EQXPROJECT="$1" + +if [[ $1 == "" ]] + then \ + echo -e "Need project name, such as:\n" + eqx-get-project-names + echo + exit +fi + +EQXPROJECTID=`eqx-get-project-uuid $EQXPROJECT` + +packet \ + project \ + delete \ + --id \ + $EQXPROJECTID \ + 2>/dev/null + +exit + diff --git a/eqx-delete-project-forced b/eqx-delete-project-forced new file mode 100755 index 0000000..d65bddd --- /dev/null +++ b/eqx-delete-project-forced @@ -0,0 +1,33 @@ +#!/bin/bash +# eqx-delete-project +# Delete an Equinix Project. +# +# Usage: +# eqx-delete-project [name] +# Example: +# eqx-delete-project fooproject + +#set -x + +EQXPROJECT="$1" + +if [[ $1 == "" ]] + then \ + echo -e "Need project name, such as:\n" + eqx-get-project-names + echo + exit +fi + +EQXPROJECTID=`eqx-get-project-uuid $EQXPROJECT` + +packet \ + project \ + delete \ + --force \ + --id \ + $EQXPROJECTID \ + 2>/dev/null + +exit + diff --git a/eqx-get-project-names b/eqx-get-project-names new file mode 100755 index 0000000..fc89712 --- /dev/null +++ b/eqx-get-project-names @@ -0,0 +1,4 @@ +#!/bin/bash + +eqx-get-projects | jq --raw-output '.[] | {name}' | grep name | cut -f 2 -d ":" | sed -e 's/ //g' -e 's/"//g' + diff --git a/eqx-get-project-uuid b/eqx-get-project-uuid new file mode 100755 index 0000000..57ceb67 --- /dev/null +++ b/eqx-get-project-uuid @@ -0,0 +1,31 @@ +#!/bin/bash +# eqx-get-project-uuid +# +# XXX not real stable way to do this... +# +# Get project UUID from a name +# +# Usage: +# eqx-get-project-uuid [name] +# Example: +# eqx-get-project-uuid fooproject + +EQXPROJECT="$1" + +if [[ $1 == "" ]] + then \ + echo -e "Need project name, such as:\n" + eqx-get-project-names + echo + exit +fi + +# XXX this... +packet \ + project \ + get \ + --project $EQXPROJECT \ + 2>/dev/null | \ + grep -w " $EQXPROJECT " | \ + cut -f 2 -d " " + diff --git a/packet-cli.json b/packet-cli.json new file mode 100644 index 0000000..f71502f --- /dev/null +++ b/packet-cli.json @@ -0,0 +1,3 @@ +{ + "token": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +}