Skip to content

Port glplex ruby script to fish

Some of the GCP functions rely upon a script that I wrote for work, called glplex. It was my first Ruby script and I wrote it in equal parts to make handling multiple GCP compute instances easier, and also as an exercise in learning Ruby. It's functional but has some stylistic issues and is a bit brittle.

It would be good to port that script to fish functions and include with this module.

Also, it would be good to enhance its handling of multiple compute instances by using the fzf utility. That introduces a new dependency, but it's a good one, and ideally I could write the functions to just error or use globs only, if the fuzzy-finder isn't installed.

Here's the interactive help from glplex:


NAME

glplex - Manage multiple nodes in the Googleplex (GCP)

SYNOPSIS

glplex [options] [**ACTION**] [**PATTERN**]

ACTION may be one of the 'gcloud compute instances' actions or extended actions (see EXTENDED ACTIONS below). If no ACTION is given, then nodes will be commanded to stop.

PATTERN is a regex to match multiple nodes by their names. If no PATTERN is given, then ACTION commands are sent to a pre-determined list of patterns and zones.

DESCRIPTION

Manage multiple "nodes" in the Googleplex (GCP compute instances), for GitLab Sandbox Cloud deployments.

The glplex script is a wrapper for the 'gcloud compute instances' command-line interface for GCP. It can pass ACTIONs to multiple nodes at a time. For more information about available ACTIONs, consult the 'gcloud compute instances' sub-command's built-in help.

Note that to contact the 'plex, you must be logged into Google Cloud:

$ gcloud auth login

EXTENDED ACTIONS

glplex also offers some actions to help with administering many nodes:

fqdn|dns|ip

Print the fully-qualified-domain-name (FQDN - if the node has one), and external IP address of all nodes matching PATTERN (in the GCP zone).

key|keys

Add your public SSH key from your gitlab.com account to the authorized_keys of each RUNNING node matching PATTERN (in the GCP zone). Assumes your gitlab username is the same as your user NAME for GCP.

ssh

Print the same information as for 'fqdn', but output in a format which you can copy/paste into your local ~/.ssh/config. Nodes can then be reached by the node name, without having to use the IP address or FQDN.

list

List node details (NAME, ZONE, TYPE ... INTERNAL_IP, EXTERNAL_IP, STATUS) of all nodes matching PATTERN (in all GCP zones).

start|up|stop|down|describe|_other_command_

These are passed along to each node matching PATTERN (in the GCP zone) as a sub-command to 'gcloud compute instances'. See that command for details. 'up|down' are synonyms for 'start|stop' (like Vagrant and Docker).

ip|address|addresses

Reserve a node's external IP address. The node must be RUNNING (so that it has and address). This will reserve each node's current external IP address, making it permanent, so that you can assign a DNS, or add it to your ~/.ssh/config.

DEFAULTS

  • Default ACTION is "stop"
  • Default HASH of GCP project is "56581c10"
  • Default NAME of GCP/GitLab user is "mlockhart"
  • Default ZONE is "us-west1-c"
  • Default is NOT to use log output, or short output

If run without the any arguments, glplex will STOP ALL NODES from a list of patterns and zones in ~/.glplex

If no configuration exists, glplex will use the following defaults:

  • 'gitlab' in the default ZONE
  • '-get-3-' in the 'us-central1-c' ZONE

options:

  • -p, --project HASH — GCP project
  • -u, --user NAME — GCP/GitLab user
  • -z, --zone ZONE — GCP zone
  • -l, --log — Add logging timestamps
  • -s, --short — Short output (for scripts)
  • -S, --skip — Skip connect to plex (use curr. GCP auth)

I may not necesarily implement all of this as a single fish function, or even port all of the ACTIONs.

Edited by Mike Lockhart | GitLab