Skip to content

Commit

Permalink
fix errcode, add freejname to auto-assign VM name
Browse files Browse the repository at this point in the history
  • Loading branch information
olevole committed Dec 10, 2024
1 parent 01cec58 commit 1035aad
Show file tree
Hide file tree
Showing 8 changed files with 1,507 additions and 290 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
src
./cbsd-mq-api
cbsd-mq-api
README.IAC.md
cbsd-mq-api-apply
client
common.yaml
hiera.yaml
init.pp
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright (c) 2021, CBSD Project
Copyright (c) 2024, CBSD Project
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
57 changes: 39 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# CBSD RESTFull API

Copyright (c) 2013-2021, The CBSD Development Team

Homepage: https://bsdstore.ru
Copyright (c) 2013-2024, The CBSD Development Team
Homepage: https://github.com/cbsd/cbsd

#### Table of Contents

Expand Down Expand Up @@ -30,7 +29,7 @@ ssh-ed25519 AAAA...yyy user2@@example.com

## Installation

Assuming you have a stock vanilla FreeBSD 13.0+ installation.
Assuming you have a stock vanilla FreeBSD 14.0+ installation.
The directives below configure a standalone installation ( single API + hoster env),
however you can use any number of physical nodes for single API.

Expand All @@ -41,7 +40,7 @@ pkg install -y cbsd cbsd-mq-router cbsd-mq-api beanstalkd git

2) Configure beanstalkd, the broker service.

Since all services are on the same server, we will specify the address 127.0.0.1
Since all services are on the same server, we will specify the address 127.0.0.1
for incoming connections and start the service:
```
sysrc beanstalkd_flags="-l 127.0.0.1 -p 11300"
Expand Down Expand Up @@ -144,18 +143,46 @@ service cbsd-mq-api start

## Usage

Valid endpoints:
### Via curl, valid endpoints:

```
curl -H "cid:<cid>" http://127.0.0.1:65531/api/v1/cluster
curl -X POST -H "Content-Type: application/json" -d @filename.json http://127.0.0.1:65531/api/v1/create/vm1
curl -H "cid:<cid>" http://127.0.0.1:65531/api/v1/status/<env>
curl -H "cid:<cid>" http://127.0.0.1:65531/api/v1/start/<env>
curl -H "cid:<cid>" http://127.0.0.1:65531/api/v1/stop/<env>
curl -H "cid:<cid>" http://127.0.0.1:65531/api/v1/destroy/<env>
```
Where `<cid>` is your token/namespace. For convenience, in a *private cluster*,
we suggest using md5 hash of your public key as <cid>.
To test, lets create simple CBSDfile, where CLOUD_KEY - is your publickey string:

To test with curl, create valid payload file, e.g. `debian12.json`:
```
cat > debian11.json <<EOF
{
"imgsize": "10g",
"ram": "1g",
"cpus": 2,
"image": "debian12",
"pubkey": "ssh-ed25519 AAAA..XXX your@localhost"
}
EOF
```
Then send it to /create endpoint:
```
curl --no-progress-meter -X POST -H "Content-Type: application/json" -d @debian12.json http://127.0.0.1:65531/api/v1/create/vm1
```

to create 'vm1' or:
```
curl --no-progress-meter -X POST -H "Content-Type: application/json" -d @debian12.json http://127.0.0.1:65531/api/v1/create/_
```

to assign a VM name automatically.

### Via CBSDfile:

To test via CBSDfile, lets create simple CBSDfile, where CLOUD_KEY - is your publickey string:
```
CLOUD_URL="http://127.0.0.1:65531"
CLOUD_KEY="ssh-ed25519 AAAA..XXX your@localhost"
Expand All @@ -181,17 +208,11 @@ cbsd destroy

See documentation for detailed information and additional examples: [https://www.bsdstore.ru/en/cbsd_api_ssi.html](https://www.bsdstore.ru/en/cbsd_api_ssi.html)

## Contributing
## Get Support

* Fork me on GitHub: [https://github.com/cbsd/cbsd-mq-api.git](https://github.com/cbsd/cbsd-mq-api.git)
* Switch to 'develop' branch
* Commit your changes (`git commit -am 'Added some feature'`)
* Push to the branch (`git push`)
* Create new Pull Request
* GitHub: https://github.com/cbsd/cbsd-mq-api/issues
* For CBSD-related support, discussion and talks, please join to Telegram CBSD usergroup channel: @cbsdofficial ( [https://t.me/cbsdofficial](https://t.me/cbsdofficial)

## Support
## Support Us

* For CBSD-related support, discussion and talks, please join to Telegram CBSD usergroup channel: @cbsdofficial
* Web link: https://t.me/cbsdofficial
* Or subscribe to mailing list by sending email to: cbsd+subscribe@lists.tilda.center
* Other contact: https://www.bsdstore.ru/en/feedback.html
* https://www.patreon.com/clonos
20 changes: 11 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import (
)

type Config struct {
ServerUrl string `json:"server_url"`
CbsdEnv string `json:"cbsdenv"`
Broker string `json:"broker"`
ImageList string `json:"imagelist"`
Recomendation string `json:"recomendation"`
Freejname string `json:"freejname"`
Cloud_images_list string `json:"cloud_images_list"`
Iso_images_list string `json:"iso_images_list"`
BeanstalkConfig `json:"beanstalkd"`
ServerUrl string `json:"server_url"`
CbsdEnv string `json:"cbsdenv"`
Broker string `json:"broker"`
ImageList string `json:"imagelist"`
Recomendation string `json:"recomendation"`
Freejname string `json:"freejname"`
Freeid string `json:"freeid"`
Cloud_images_list string `json:"cloud_images_list"`
Iso_images_list string `json:"iso_images_list"`
Flavors_list string `json:"flavors_list"`
BeanstalkConfig `json:"beanstalkd"`
}

func LoadConfiguration(file string) (Config, error) {
Expand Down
8 changes: 5 additions & 3 deletions etc/cbsd-mq-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
"logfile": "/dev/stdout",
"recomendation": "/usr/local/cbsd/modules/api.d/misc/recomendation.sh",
"freejname": "/usr/local/cbsd/modules/api.d/misc/freejname.sh",
"server_url": "https://127.0.0.1",
"freeid": "/usr/local/cbsd/modules/api.d/misc/freeid.sh",
"server_url": "http://127.0.0.1:65531",
"cloud_images_list": "/usr/local/etc/cbsd_api_cloud_images.json",
"iso_images_list": "/usr/local/etc/cbsd_api_iso_images.json",
"flavors_list": "/usr/local/etc/cbsd_flavors.json",
"beanstalkd": {
"uri": "127.0.0.1:11300",
"tube": "cbsd_zpool1",
"reply_tube_prefix": "cbsd_zpool1_result_id",
"tube": "cbsd_mother_olevole_ru",
"reply_tube_prefix": "cbsd_mother_olevole_ru_result_id",
"reconnect_timeout": 5,
"reserve_timeout": 5,
"publish_timeout": 5,
Expand Down
35 changes: 29 additions & 6 deletions etc/cbsd_api_cloud_images.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
{
"images": [
"alma9",
"arch22",
"centos7",
"centos8",
"debian10",
"centos9",
"debian11",
"debian12",
"devuan5",
"dflybsd6",
"euro9",
"fedora39",
"fedora40",
"fedora41",
"freebsd13_ufs",
"freebsd13_zfs",
"freebsd14_ufs",
"freebsd14_zfs",
"freebsd15_ufs",
"freebsd15_zfs",
"freefire14_ufs",
"freepbx",
"ghostbsd24",
"homeass",
"jail",
"kali2024",
"k8s",
"netbsd9",
"netbsd10",
"openbsd7",
"opnsense21",
"opnsense22",
"oracle7",
"oracle8",
"rocky8",
"ubuntu20"
"oracle9",
"rocky9",
"ubuntu22",
"ubuntu22_vdi",
"ubuntu24",
"ubuntu24_vdi",
"xigmanas13"
]
}
}
Loading

0 comments on commit 1035aad

Please sign in to comment.