init repo
This commit is contained in:
commit
58fdaa0102
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Jesús Pérez Lorenzo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
259
README.md
Normal file
259
README.md
Normal file
@ -0,0 +1,259 @@
|
||||
|
||||
<img style="margin-top: 1em;width: 500px;border: 0" alt="Fork me on GitHub"
|
||||
src="logo/upclapiflow.svg?sanitize=true"></a>
|
||||
|
||||
# Declarative [UpCloud](https://upcloud.com) Go API with YAML
|
||||
|
||||
> This is an abbreviate version of [UpClapi](https://github.com/JesusPerez/upclapi.git)
|
||||
> **Upclapiflow** is more for production management rather than [CD/CI](https://en.wikipedia.org/wiki/CI/CD) where [UpClapi](https://github.com/JesusPerez/upclapi.git) has more power and sense.
|
||||
|
||||
This was created for:
|
||||
|
||||
- start,stop [UpCloud servers](https://upcloud.com/products/cloud-servers/).
|
||||
- modify, delete [UpCloud storages](https://upcloud.com/products/maxiops-storage/).
|
||||
- Run commands with **ssh** in [UpCloud servers](https://upcloud.com/products/cloud-servers/).
|
||||
- create servers [Ansible inventories](https://docs.ansible.com/ansible/latest/index.html)
|
||||
|
||||
> Tasks can be <u>declared</u> and <u>grouped together</u> in [YAML](https://en.wikipedia.org/wiki/YAML) files, some of them can use target resource UUID, it shares same layout and content files with [UpClapi](https://github.com/JesusPerez/upclapi.git)
|
||||
|
||||
All in a [GO](https://golang.org/) binary program thanks to [Official UpCloudLtd GO API](https://github.com/UpCloudLtd/upcloud-go-api)
|
||||
|
||||
|
||||
It clearly does not try to replace tools like [Terraform](https://www.terraform.io/) or [Ansible](https://docs.ansible.com/),etc to manage **Infraestructure** rather as an alternative for some cases, like:
|
||||
|
||||
- servers tasks: start, stop, delete
|
||||
- float ip management
|
||||
- run commands on servers via **ssh** (output is captured)
|
||||
- resources lists in **json**
|
||||
|
||||
## Requirements for build
|
||||
|
||||
- Go `1.11+`
|
||||
- Go Modules
|
||||
|
||||
## Build from source
|
||||
|
||||
- Clone this repository and go to folder:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/JesusPerez/upclapiflow.git
|
||||
cd upclapiflow
|
||||
```
|
||||
|
||||
- Build:
|
||||
|
||||
```bash
|
||||
make
|
||||
```
|
||||
|
||||
- Install ($GOPATH/bin):
|
||||
|
||||
```bash
|
||||
make install
|
||||
```
|
||||
|
||||
#### Run examples
|
||||
|
||||
- **UpCloud** Credentilas
|
||||
Use evironment variables like this:
|
||||
|
||||
```bash
|
||||
export UPCLOUD_USERNAME="apu-username"
|
||||
export UPCLOUD_PASSWORD="api-password"
|
||||
```
|
||||
If creadentials are not found, this message will be displayed:
|
||||
|
||||
```txt
|
||||
Auth info: Username must be specified
|
||||
or
|
||||
Auth info: Password must be specified
|
||||
```
|
||||
|
||||
As an option it is possible to encrypt sensitive informations like:
|
||||
|
||||
- Credentials (username/password)
|
||||
- Data config file in yaml
|
||||
|
||||
- Help
|
||||
|
||||
```bash
|
||||
# Getting help
|
||||
go run ./... --help
|
||||
```
|
||||
|
||||
```txt
|
||||
-c string
|
||||
command to run [
|
||||
infoserver, restartserver, startserver, stopserver,
|
||||
infofloatip, movefloatip,
|
||||
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
|
||||
```
|
||||
|
||||
- Info Server
|
||||
```bash
|
||||
./build/upclapi -c infoserver -f [yaml-config-file]
|
||||
```
|
||||
|
||||
```bash
|
||||
./build/upclapi -c infoserver -id server-hostname
|
||||
```
|
||||
|
||||
- Move a Float IP
|
||||
```bash
|
||||
./build/upclapi -c movefloatip -f [yaml-config-file]
|
||||
```
|
||||
|
||||
```bash
|
||||
./build/upclapi -c movefloatip -id float-ip-address::target-hostname
|
||||
```
|
||||
|
||||
- Run SSH on Server
|
||||
(yaml-config-file has to include *ssh** config section)
|
||||
```bash
|
||||
./build/upclapi -c runssh -f [yaml-config-file] -ssh remote-command-to-execute
|
||||
```
|
||||
|
||||
> User account persmissions may not allow some tasks dto create or deleted
|
||||
> To fully manage, UpCloud owner is mandatory
|
||||
|
||||
- For show info about coverage (will open in browser):
|
||||
|
||||
```bash
|
||||
make show_coverage
|
||||
```
|
||||
|
||||
- That's all! 🎉
|
||||
|
||||
## YAML Config Example
|
||||
|
||||
```yaml
|
||||
floatIP: float-ip-for-servers
|
||||
# "hostname" should start with hostPrefix or comment/remove this setting
|
||||
hostPrefix: prefix-for-severs
|
||||
# Could be same as hostPrefix, like "server" for server01, server02, etc
|
||||
mainName: main-global/cluster/floatIP-name
|
||||
servers:
|
||||
# Repeat this section for each host
|
||||
- hostname: test.example.com
|
||||
title: "Host title"
|
||||
# Cluster definition for this server not mandatory
|
||||
cluster:
|
||||
role: master # role in ansible inventory
|
||||
## SSH credentials to run commands not mandatory
|
||||
ssh:
|
||||
host: hostName-or-ip
|
||||
user: root
|
||||
password: ""
|
||||
type: key # can use password
|
||||
keyPath: path-to-id_rsa-key-file
|
||||
port: 22
|
||||
# List of Tags (management can be restricted for user account)
|
||||
tags:
|
||||
- server
|
||||
loginUser:
|
||||
sshKeys: # ssh-rsa public keys to add
|
||||
- ssh-rsa ....
|
||||
|
||||
timeZone: "UTC"
|
||||
zone: nl-ams1 # UpCloud Zone
|
||||
|
||||
# If this sever can use floatIP set to 1
|
||||
useFloatIP: 1
|
||||
# List of Networks, at least one
|
||||
networks:
|
||||
- access: utility # only if is need it
|
||||
family: IPv4
|
||||
- access: public # only if is need it
|
||||
family: IPv4
|
||||
- access: private # if is going to use SDN
|
||||
family: IPv4
|
||||
network: UUID-SDN-NETWORK
|
||||
ipaddress: SDN-ip-address-or-use-SDN-DHCP
|
||||
|
||||
```
|
||||
|
||||
## Environment
|
||||
|
||||
Main vars:
|
||||
|
||||
[UpCloud API](https://developers.upcloud.com) 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
|
||||
|
||||
- [Jesús Pérez](https://github.com/jesusperez).
|
||||
|
||||
## Article assistance
|
||||
|
||||
If you want to say «thank you»:
|
||||
|
||||
1. Twit about article [on your Twitter](https://twitter.com/intent/tweet?text=Let%27s%20write%20config%20for%20your%20Golang%20web%20app%20on%20right%20way%20%E2%80%94%20YAML%20%F0%9F%91%8C%20https%3A%2F%2Fdev.to%2Fkoddr%2Flet-s-write-config-for-your-golang-web-app-on-right-way-yaml-5ggp).
|
||||
2. Add a GitHub Star and make Fork to this repository.
|
||||
3. Donate some money to project author via PayPal: [@paypal.me/](https://paypal.me/).
|
||||
4. Join UpCloud at my [referral link](https://upcloud.com/signup/?promo=CVR337) (your profit is **\$25** credits and I will receive \$50 worth of free credits).
|
||||
|
||||
Thanks for your support! 😘
|
||||
|
||||
|
||||
## References
|
||||
|
||||
[UpCloudLtd go API](https://github.com/UpCloudLtd/upcloud-go-api)
|
||||
|
||||
[Let's write config for your Golang web app on right way — YAML 👌](https://dev.to/koddr/let-s-write-config-for-your-golang-web-app-on-right-way-yaml-5ggp). Published @ 13 Feb 2020.
|
||||
|
||||
[Go language: crypto / SSH executes remote commands](https://developpaper.com/go-language-crypto-ssh-executes-remote-commands/)
|
||||
|
||||
[golang-enter-ssh-sudo-password-on-prompt-or-exit](https://gist.github.com/boyzhujian/73b5ecd37efd6f8dd38f56e7588f1b58)
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
1
logo/upclapiflow.svg
Normal file
1
logo/upclapiflow.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 358.28 53.3"><defs><style>.cls-1{font-size:47px;fill:#666;font-family:SourceSansPro-SemiBold, Source Sans Pro;font-weight:600;}.cls-2,.cls-7{fill:#999;}.cls-3{letter-spacing:-0.02em;}.cls-4{fill:#444;letter-spacing:0em;}.cls-5,.cls-6{fill:#7b00ff;}.cls-6{letter-spacing:0.04em;}.cls-7{letter-spacing:-0.01em;}</style></defs><title>Recurso 3</title><g id="Capa_2" data-name="Capa 2"><g id="Capa_1-2" data-name="Capa 1"><text class="cls-1" transform="translate(0 39.01) scale(1.09 1)">{<tspan class="cls-2" x="15.23" y="0">...</tspan><tspan class="cls-3" x="54" y="0">}</tspan><tspan class="cls-4" x="68.29" y="0"> </tspan><tspan class="cls-5" x="77.69" y="0">UpC</tspan><tspan class="cls-6" x="162.05" y="0">l</tspan><tspan x="176.67" y="0">api</tspan><tspan class="cls-2" x="239.74" y="0">fl</tspan><tspan class="cls-7" x="267.38" y="0">o</tspan><tspan class="cls-2" x="292.9" y="0">w</tspan></text></g></g></svg>
|
After Width: | Height: | Size: 966 B |
Loading…
Reference in New Issue
Block a user