• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H02-Dec-2021-53

etc/H02-Dec-2021-4039

rc.d/H02-Dec-2021-8163

src/H03-May-2022-1,2701,032

vendor/H03-May-2022-98,95277,040

.gitignoreH A D02-Dec-202137 54

LICENSEH A D02-Dec-20211.3 KiB2620

README.mdH A D02-Dec-20215.4 KiB198155

beanstalk.goH A D02-Dec-20212.1 KiB10076

build.shH A D02-Dec-2021680 2820

common.goH A D02-Dec-2021417 2620

config.goH A D02-Dec-2021927 4234

main.goH A D02-Dec-202131.5 KiB1,171910

README.md

1# CBSD RESTFull API
2
3Copyright (c) 2013-2021, The CBSD Development Team
4
5Homepage: https://bsdstore.ru
6
7#### Table of Contents
8
91. [Project Description - What does the project do?](#description)
102. [Installation - HowTo start](#installation)
113. [Usage - Configuration options and additional functionality](#usage)
124. [Contributing - Contribute to the project](#contributing)
135. [Support - Mailing List, Talks, Contacts](#support)
14
15
16## Description
17
18Provides a simplified API for creating and destroying CBSD virtual environments.
19
20## Errata
21
22By default, all actions are permitted for all requests.
23Through the `-allowlist <whitelist_file>` parameter you can limit the number of permissible public keys/CID.
24Format of <whitelist_file> similar to authotized_keys: one key per line, e.g:
25
26```
27ssh-ed25519 AAAA...xxx your_name@@your.domain
28ssh-ed25519 AAAA...yyy user2@@example.com
29```
30
31## Installation
32
33Assuming you have a stock vanilla FreeBSD 13.0+ installation.
34The directives below configure a standalone installation ( single API + hoster env),
35however you can use any number of physical nodes for single API.
36
371) Install packages:
38```
39pkg install -y cbsd cbsd-mq-router cbsd-mq-api beanstalkd git
40```
41
422) Configure beanstalkd, the broker service.
43
44  Since all services are on the same server, we will specify the address 127.0.0.1
45  for incoming connections and start the service:
46```
47sysrc beanstalkd_flags="-l 127.0.0.1 -p 11300"
48service beanstalkd enable
49service beanstalkd restart
50```
51
523) Configure CBSD as usual:
53```
54env workdir=/usr/jails /usr/local/cbsd/sudoexec/initenv
55```
56
574) Configure MQ router
58
59First, get hoster FQDN via `hostname` command.
60Let's say your host has a name: apitest.my.domain
61
62Open /usr/local/etc/cbsd-mq-router.json in any favorite editor and set
63"tube" and "reply_tube_prefix" params ( cbsd_<hostname_without_dot> and cbsd_<hostname_without_dot>_result_id ), e.g:
64
65```
66{
67    "cbsdenv": "/usr/jails",
68    "cbsdcolor": false,
69    "broker": "beanstalkd",
70    "logfile": "/dev/stdout",
71    "recomendation": "/usr/local/cbsd/modules/api.d/misc/recomendation.sh",
72    "freejname": "/usr/local/cbsd/modules/api.d/misc/freejname.sh",
73    "server_url": "https://127.0.0.1",
74    "cloud_images_list": "/usr/local/etc/cbsd_api_cloud_images.json",
75    "iso_images_list": "/usr/local/etc/cbsd_api_iso_images.json",
76    "beanstalkd": {
77      "uri": "127.0.0.1:11300",
78      "tube": "cbsd_zpool1",
79      "reply_tube_prefix": "cbsd_zpool1_result_id",
80      "reconnect_timeout": 5,
81      "reserve_timeout": 5,
82      "publish_timeout": 5,
83      "logdir": "/var/log/cbsdmq"
84    }
85}
86
87```
88
89  `cloud_images_list` - The path to the json  file, which is displayed upon /images query - list of avaliable images.
90                        See etc/cbsd_api_cloud_images.json as sample.
91
925) Start MQ router:
93```
94service cbsd-mq-router enable
95service cbsd-mq-router start
96```
97
986) Install CBSD API module:
99```
100cbsd module mode=install api
101echo 'api.d' >> ~cbsd/etc/modules.conf
102cbsd initenv
103```
104
1057) Configure CBSD API module.
106
107Copy configuration sample to work dir:
108```
109cp -a /usr/local/cbsd/modules/api.d/etc/api.conf ~cbsd/etc/
110cp -a /usr/local/cbsd/modules/api.d/etc/bhyve-api.conf ~cbsd/etc/
111cp -a /usr/local/cbsd/modules/api.d/etc/jail-api.conf ~cbsd/etc/
112```
113
114Open ~cbsd/etc/api.conf in any favorite editor and set "server_list=" to server FQDN, e.g:
115```
116...
117server_list="apitest.my.domain"
118...
119```
120
121Set 'cbsd' user permission for ~cbsd/etc/api.conf file:
122```
123chown cbsd:cbsd ~cbsd/etc/api.conf
124```
125
126Here you can check that the API module scripts works:
127```
128su -m cbsd -c '/usr/local/cbsd/modules/api.d/misc/recomendation.sh'
129```
130must return the host from server_list ( apitest.my.domain )
131
132```
133su -m cbsd -c '/usr/local/cbsd/modules/api.d/misc/freejname.sh'
134```
135must return the unique name 'envX'.
136
1378) Configure RestAPI daemon:
138```
139mkdir -p /var/db/cbsd-api /usr/jails/var/db/api/map
140chown -R cbsd:cbsd /var/db/cbsd-api /usr/jails/var/db/api/map
141service cbsd-mq-api enable
142service cbsd-mq-api start
143```
144
145## Usage
146
147Valid endpoints:
148
149```
150curl -H "cid:<cid>" http://127.0.0.1:65531/api/v1/cluster
151curl -H "cid:<cid>" http://127.0.0.1:65531/api/v1/status/<env>
152curl -H "cid:<cid>" http://127.0.0.1:65531/api/v1/start/<env>
153curl -H "cid:<cid>" http://127.0.0.1:65531/api/v1/stop/<env>
154curl -H "cid:<cid>" http://127.0.0.1:65531/api/v1/destroy/<env>
155```
156Where `<cid>` is your token/namespace. For convenience, in a *private cluster*,
157we suggest using md5 hash of your public key as <cid>.
158To test, lets create simple CBSDfile, where CLOUD_KEY - is your publickey string:
159```
160CLOUD_URL="http://127.0.0.1:65531"
161CLOUD_KEY="ssh-ed25519 AAAA..XXX your@localhost"
162
163jail_minio1()
164{
165	imgsize="10g"
166	pkg_bootstrap=0
167}
168```
169
170Run:
171```
172sudo cbsd up
173```
174
175After jail start you can use:
176```
177cbsd login
178cbsd status
179cbsd destroy
180```
181
182See 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)
183
184## Contributing
185
186* Fork me on GitHub: [https://github.com/cbsd/cbsd-mq-api.git](https://github.com/cbsd/cbsd-mq-api.git)
187* Switch to 'develop' branch
188* Commit your changes (`git commit -am 'Added some feature'`)
189* Push to the branch (`git push`)
190* Create new Pull Request
191
192## Support
193
194* For CBSD-related support, discussion and talks, please join to Telegram CBSD usergroup channel: @cbsdofficial
195* Web link: https://t.me/cbsdofficial
196* Or subscribe to mailing list by sending email to: cbsd+subscribe@lists.tilda.center
197* Other contact: https://www.bsdstore.ru/en/feedback.html
198