bin | ||
logo | ||
.gitignore | ||
floatip.go | ||
go.mod | ||
go.sum | ||
inventory.go | ||
LICENSE | ||
main.go | ||
Makefile | ||
networks.go | ||
prices.go | ||
README.md | ||
rel_env | ||
run.go | ||
servers.go | ||
ssh.go | ||
storage.go | ||
tags.go |
{...} UpClapi
Declarative & command-line interface for UpCloud resources
This was created since December 2020 to:
- to use YAML config definition files for resources and services
- create,delete,start,stop UpCloud servers.
- modify, delete UpCloud storages.
- Run commands with ssh in UpCloud servers.
- create servers Ansible inventories
TskSrvcs can be declared and grouped together in YAML files, some of them can use target resource UUID
All in a GO binary program thanks to Official UpCloudLtd GO API
It clearly does not try to replace tools like Terraform or Ansible,etc to manage Infraestructure rather as an alternative for some cases, like:
- simple servers provisioning
- servers tsksrvcs: start, stop, delete
- modify network interfaces
- float ip management
- modify storage
- automatic resources scale
- run commands on servers via ssh (output is captured)
- create Ansible inventories
- resources lists in json
- prototyping
- resources costs ...
- As a provider tool for other LibreClouds Klouds tools: CloudMandala and Zteron
Since March 2021 UpCloud made available a UpCloud CLI - upctl to allow resources control from command line. {...}UpClapi was create to be used with a Declarative approach to manage infrastructures although some tasks can be solved with imperative command calls, resources relationship and their dependencies should be set and declared somewhere at least for monitoring,management,etc.
Both developments (upctl and {...}UpClapi) use Official UpCloudLtd GO API extensively.
{...}UpClapi is used as a tool to provision and manage UpCloud ressources for LibreClouds Klouds with CloudMandala and Zteron as major tools.
Requirements for build
- Go
1.16+
- Go Modules defined in go.mod
Why is named like {...}UpClapi
This development is fully focus on UpCloud as resources provider and use extensively Official UpCloudLtd GO API. So this is what it use and his focus, but {...} define what it is, a group of resources than can be created, set and manage by custom definition or declaration with a name you chose.
Short version, can be interpreted as:
whatever group {...} of UpCloud resources managed via UpCloud API
Download Release binary
1 - Copy attachment url from releases page
2 - Use this shell command changing attachment URL:
curl -sLS "** attachment URL **" | gunzip > upclapi ; chmod +x upclapi
3 - Test it by running in shell:
./upclapi -h
4 - Move this file to something like: /usr/local/bin or wherever you like.
Build from source
- Clone this repository and go to folder:
git clone https://rlung.librecloud.online/LibreCloud/Upclapi.git
cd Upclapi
- Build:
make
- Install ($GOPATH/bin):
make install
Run examples
- UpCloud Credentilas Use evironment variables like this:
export UPCLOUD_USERNAME="api-username"
export UPCLOUD_PASSWORD="api-password"
As an alternative this can be set as in an enviroment file with paths: /etc/upcloud/.env or /usr/local/etc/upcloud/.env
Another alternative is to use default UpCloud CLI - upctl config set path: $HOME/.config/upctl.yaml
If creadentials are not found, this message will be displayed:
Auth info: Username must be specified
or
Auth info: Password must be specified
As a more secure option it is possible to encrypt sensitive informations like:
-
Credentials (username/password)
-
Data config file in yaml
-
Version
# Getting version
upclapi version
# or upclapi -v
- Help
# Getting help
upclapi --help
# or upclapi -h
Usage of upclapi:
-c string
command to run [
createserver, infoserver, restartserver, startserver, stopserver, modifyserver, deleteserver,
infofloatip, movefloatip, modifyip,
infotags, addtags, deletetags (use -t keep to keep storages)
liststorages, fixstorage (-t size | part0 | part1 | final), deletestorage, modifystorage, createstorageimage (-t title),
inventory, pubhosts, prvhosts
runssh, runcmd
] (default "infoserver")
-cmd string
run [ssh] command
-f string
path to data file (default "datacfg.yaml")
-id string
resource name or uuid
-kdr string
use coder
-o string
output format (attached for infofloatip)
-sid string
ssh id for ssh commands (or defaul id_rsa)
-t string
target item for command
-v version
- Create Server
./build/upclapi -c createserver -f [yaml-config-file]
- Info Server
./build/upclapi -c infoserver -f [yaml-config-file]
./build/upclapi -c infoserver -id server-hostname
- Move a Float IP
./build/upclapi -c movefloatip -f [yaml-config-file]
- Get attached IP to Float IP
./build/upclapi -c infofloatip -id float-ip ( or -f [yaml-config-file] ) -o attached
./build/upclapi -c movefloatip -id float-ip-address::target-hostname
- Run SSH on Server (yaml-config-file or -id flag) if no -sid flag id_pub in HOME will be used by default
./build/upclapi -c runssh -f [yaml-config-file] -cmd remote-command-to-execute [-sid ssh/key_filename]
./build/upclapi -c runssh -id hostname -cmd remote-command-to-execute [-sid ssh/key_filename]
- Create Servers Ansible Inventory (yaml-config-file has to include cluster config section)
./build/upclapi -c inventory -f [yaml-config-file]
User account persmissions may not allow some tsksrvcs to create or deleted To fully manage, UpCloud owner account is mandatory
- To show info about coverage (will open in browser):
make show_coverage
- That's all! 🎉
YAML resources declaration
# Controller to manage and monitor
cntrllrs:
- cldPath: relative-path-for-controller
host: hostname
masterPath: ''
sshaccess:
host: hostname
keyPath: ''
password: ''
port: 22
user: ssh-user
utype: key
domainName: domain-name
floatIP: ''
group: group-name
group_path: relative-group-path
hostPrefix: hostprefix-
mainName: main-name
# UpCloud as provider
provider: upcloud
resolvDNS: ''
servers:
# Repeat this section for each host
- apps: # Apps to install
- critical: no
liveness: ''
name: none
path: ''
req: ''
target: ''
arch: linux_amd64
backup:
- ''
clients:
- ''
cluster:
role: role-tag
hostname: hostname
loginUser:
sshKeys:
- ''
metadata: 1
networks:
- access: utility
family: IPv4
source_ip_filtering: yes
- access: public
family: IPv4
source_ip_filtering: yes
- access: private # If use SDN
family: IPv4
ipaddress: 'ip-for-sdn'
network: "sdn-uuid"
source_ip_filtering: no
plan: "1xCPU-1GB" # UpCloud server plan
rules:
- ''
sshAccess:
host: hostname
keyPath: ''
password: ''
port: 22
user: "ssh-user"
utype: key
storages:
- action: clone
size: 20
finalSize: 20 # These 3 lines can be used to create partitions
makefs: ""
partSizes: ''
source: source-name
storage: UUID-for-source-image
tier: maxiops
title: Title-for-this-storage
tags:
- cd
- ci
timeZone: UTC
title: titls-of-this-host
tsksrvcs: # Tasks & Services to install,maintain,monitor, etc.
- critical: no
liveness: ''
name: sysconfig
path: ''
req: ''
target: ''
useFloatIP: false
userData: ''
zone: es-mad1 # UpCloud Zone
Attributes and values are declared in main.go and yaml parsed.
A lot of definitions (apps, tsksrvcs, cntrllrs, etc.) are used mainly for other LibreClouds Klouds tools: CloudMandala and Zteron. These Klouds tools developed in Rust declare attributes and values with Dhall language and then converted to formats like yaml and json (so types are consistent and grouped accordly).
{...}UpClapi consumes ONLY yaml config/declaration files, and can be used for standalone proposal with yaml resources declaration files (in such case set empty definitions for: apps, tsksrvcs, cntrllrs)
Environment
Main vars:
UpCloud API connetions
-
UPCLOUD_USERNAME with username
-
UPCLOUD_PASSWORD with password
-
KUPCLAPI includes user + password encrypted
Use to preset settings:
Arg | Env. var |
---|---|
-c | UPCLAPI_COMMAND |
-f | UPCLAPI_DATACFG |
-id | UPCLAPI_ID |
-cmd | UPCLAPI_RUNCMD |
-kdr | UPCLAPI_ENCODER |
-o | UPCLAPI_OUT |
Coders and encoders
It is possible to encrypt sensitive informations like:
- Credentials (username/password)
- Data config file in yaml
Coders are called using operating system command (exec)
Tecoder from ZTerton backend developments is fully supported
Coder definition to be used:
var | content |
---|---|
cmd | command-path |
abbrv | abbreviation |
decoder | decoder-args |
fdecoder | file-decoder-args |
encoder | encoder-args |
fencoder | file-encoder-args |
Author
Article assistance
If you want to say «thank you»:
- Twit about article on your Twitter.
- Add a GitHub Star and make Fork to this repository.
- Donate some money to project author via PayPal: @paypal.me/.
- Join UpCloud at my referral link (your profit is $25 credits and I will receive $50 worth of free credits).
Thanks for your support! 😘
References
Let's write config for your Golang web app on right way — YAML 👌. Published @ 13 Feb 2020.
Go language: crypto / SSH executes remote commands
golang-enter-ssh-sudo-password-on-prompt-or-exit
License
MIT