Giter VIP home page Giter VIP logo

goclowdy's Introduction

GoClowdy

Access and automate chores related to VMs and Machine Images.

goclowdy provides easy-to-use Go wrappers for accessing the inventory of VM:s and VM Machine images with a very terse and compact wrapper code for the parts that otherwise cause a lot of code indirection and verbosity with GCP native APIs. It can equally be used to build CLI apps, web apps and cloud functions.

Pre-requisites

  • Go runtime and compiler (Version 1.16 preferred)
  • Make utility

Set environment variables for project and JSON credentials:

  • GCP_PROJECT - The GCP Project from where the GCP artifacts are going to be accessed
  • GOOGLE_APPLICATION_CREDENTIALS - The JSON credentials for accessing CGP org/project.

Building Main Executable

This should build the main executable by name 'goclowdy':

go build

Code it short and it will (in future) contain features that lead to deletion of machine images - please review and understand the code before running it.

Configuration file

Config file supports following config variables (for MIs):

  • Project - The GCP Project to scope operation to (Can be overriden by --project CL parameter for most operations)
  • CredF - Credentials file (GCP service account JSON key, be sure to have only user access to this file)
  • DelOK - Allow deleting machine images (default: false). This also works as a flag for allowing to create a new MI (machine image) by same name (by deleting old first)
  • Debug - Increase verbosity for runtime messages (default: false)
  • NameREStr - Machine image "standard name" REgExp String (default: none, must be valid RE). If pattern is set, **only the machine images that match this pattern will be considered for deletion (MI:s that do not are always kept). When this string is empty / not present, filtering and classification by "standard name" is disabled.
  • HostREStr - Machine image name patterns with hostname and creation time RE capture groups (i.e. "(...)...(...)" ) for capturing / deriving:
    • hostname capture -> what VM MI belongs to
    • creation time capture -> when the MI was created (ISO time, optional capture, this is more accurately reflected by mi.GetCreationTimestamp())
  • Machine image Retention time config vars (all times given as hours):
    • KeepMinH - Keep minumum time (all MIs below this age get kept, default: 168 hrs => 7 days/1 week)
    • KeepMaxH - Keep maximum time (all MIs above this age get deleted, default: 133320 hrs => 78(+) weeks)
    • WD_keep - The weekday on which to keep (or take) the backup (for weekly backup)
    • MD_keep - The day-of-the-month on which to keep (or take) the backup (for montly backup)
  • StorLoc - Storage location for creating MI:s in (default: none, e.g. "us" for later us-wide multiregion access)
  • ChunkDelSize - Chunk size for chunked deletion (or trigger work-queue based deletion by using value -1, See also WorkerLimit)
  • WorkerLimit - The number of concurrent workers that should be maintained when using work-queue

Overriding settings from environment (and CL)

The following config vars can be override by environment or by CL params:

Config var Env. Var. Notes
CredF GOOGLE_APPLICATION_CREDENTIALS
Project GCP_PROJECT
NameREStr MI_STDNAME No cap groups
HostREStr MI_HOSTPATT 2 cap groups for Hname, CTime
NA GCP_VM_NAMEPATT For
DelOK MI_DELETE_EXEC
ChunkDelSize MI_CHUNK_DEL_SIZE

Running the code

Executable grsc currently supports 2 subcommands:

  • vmlist - List virtual machines in project and revirew their current backups
  • milist - list machine images and classify them as keepers or to-be-deleted based on simple backup retainment policy.

TODO

  • Enahance documentation, the config options of modules/ CLI utils.
  • Add subcomands / use cases to CLI utility

goclowdy's People

Contributors

ohollmen avatar jordan-olthoff avatar

Watchers

 avatar

Forkers

jordan-olthoff

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.