Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
labmanager-systemd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto LIVIO BECCARIA
labmanager-systemd
Commits
e4a3a169
Commit
e4a3a169
authored
1 year ago
by
bta
Browse files
Options
Downloads
Patches
Plain Diff
get-config: WIP for
#2
: use curl options to retry requests.
parent
db73f222
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/get-config
+6
-6
6 additions, 6 deletions
bin/get-config
with
6 additions
and
6 deletions
bin/get-config
+
6
−
6
View file @
e4a3a169
...
...
@@ -49,7 +49,7 @@ function debug() {
# authenticate and get the token
function
getTokenJSON
()
{
# store the whole response with the status at the end
HTTP_RESPONSE
=
$(
curl
-s
-k
-w
"HTTPSTATUS:%{http_code}"
--max-time
10
-X
POST
-H
"Content-Type: application/json"
-d
"{
\"
login
\"
:
\"
guest
\"
,
\"
pwd
\"
:
\"\"
}"
${
API_BASE_URL
}
/login
)
HTTP_RESPONSE
=
$(
curl
--retry-all-errors
--retry
5
-s
-k
-w
"HTTPSTATUS:%{http_code}"
--max-time
10
-X
POST
-H
"Content-Type: application/json"
-d
"{
\"
login
\"
:
\"
guest
\"
,
\"
pwd
\"
:
\"\"
}"
${
API_BASE_URL
}
/login
)
ret
=
$?
if
[[
$ret
!=
0
]]
;
then
...
...
@@ -92,14 +92,14 @@ stop() {
# get configuration from WS
getConfigVars
()
{
echo
"Authenticating to WS..."
TOKEN_JSON
=
`
retry
getTokenJSON
`
TOKEN_JSON
=
`
getTokenJSON
`
if
[[
"
$TOKEN_JSON
"
==
""
]]
;
then
return
2
fi
TOKEN
=
`
echo
${
TOKEN_JSON
}
| jsonValue token 1
`
MACHINE_NAME
=
`
hostname
`
echo
"Getting machine configuration..."
MACHINE_JSON
=
`
retry
/usr/bin/curl
-s
-k
--max-time
10
-H
"Authorization: Bearer
${
TOKEN
}
"
-X
GET
${
API_BASE_URL
}
/machines/name/
${
MACHINE_NAME
}
`
MACHINE_JSON
=
`
/usr/bin/curl
--retry-all-errors
--retry
5
-s
-k
--max-time
10
-H
"Authorization: Bearer
${
TOKEN
}
"
-X
GET
${
API_BASE_URL
}
/machines/name/
${
MACHINE_NAME
}
`
MACHINE_ID
=
`
echo
$MACHINE_JSON
| jsonValue
id
1
`
MACHINE_CONFIGS_ID
=
`
echo
$MACHINE_JSON
| jsonValue configs_id 1
`
CONFIG_NAME
=
`
echo
$MACHINE_JSON
| jsonValue name 2
`
...
...
@@ -125,7 +125,7 @@ getConfigFile() {
echo
"Error downloading config file (machine_id empty, maybe it is not in LabManager's DB)"
return
1
fi
HTTP_STATUS
=
`
retry
/usr/bin/curl
-s
-k
-w
"%{http_code}"
-o
/local/esame-machine.conf
--max-time
10
--header
"Authorization: Bearer
${
TOKEN
}
"
-X
GET
${
API_BASE_URL
}
/machines/
${
MACHINE_ID
}
/configfile
`
HTTP_STATUS
=
`
/usr/bin/curl
--retry-all-errors
--retry
5
-s
-k
-w
"%{http_code}"
-o
/local/esame-machine.conf
--max-time
10
--header
"Authorization: Bearer
${
TOKEN
}
"
-X
GET
${
API_BASE_URL
}
/machines/
${
MACHINE_ID
}
/configfile
`
if
[[
$HTTP_STATUS
-ne
200
]]
then
echo
"Error downloading config file (http_status=
$HTTP_STATUS
)"
...
...
@@ -139,7 +139,7 @@ getConfigFile() {
getIpConfigFile
()
{
echo
"Downloading machine iptables config file..."
# get ipconfig file
HTTP_STATUS
=
`
retry
/usr/bin/curl
-s
-k
-w
"%{http_code}"
-o
/local/iptables
--max-time
10
--header
"Authorization: Bearer
${
TOKEN
}
"
-X
GET
${
API_BASE_URL
}
/machines/
${
MACHINE_ID
}
/ipconfigfile
`
HTTP_STATUS
=
`
/usr/bin/curl
--retry-all-errors
--retry
5
-s
-k
-w
"%{http_code}"
-o
/local/iptables
--max-time
10
--header
"Authorization: Bearer
${
TOKEN
}
"
-X
GET
${
API_BASE_URL
}
/machines/
${
MACHINE_ID
}
/ipconfigfile
`
if
[[
$HTTP_STATUS
-ne
200
]]
then
echo
"Error downloading iptables config file (http_status=
$HTTP_STATUS
)"
...
...
@@ -152,7 +152,7 @@ getIpConfigFile() {
updateCurrentConfigId
()
{
# Update this machine's current config id
HTTP_STATUS
=
`
/usr/bin/curl
-s
-k
-w
"%{http_code}"
-o
/dev/null
--max-time
10
-H
"Content-Type: application/json"
-H
"Authorization: Bearer
${
TOKEN
}
"
\
HTTP_STATUS
=
`
/usr/bin/curl
--retry-all-errors
--retry
5
-s
-k
-w
"%{http_code}"
-o
/dev/null
--max-time
10
-H
"Content-Type: application/json"
-H
"Authorization: Bearer
${
TOKEN
}
"
\
-X
PUT
-d
"{
\"
current_configs_id
\"
:
\"
$MACHINE_CONFIGS_ID
\"
}"
${
API_BASE_URL
}
/machines/
${
MACHINE_ID
}
/currentconfig
`
if
[[
$HTTP_STATUS
-ne
200
]]
...
...
This diff is collapsed.
Click to expand it.
Bussi Andrea
@bta
mentioned in commit
b37747a9
·
1 year ago
mentioned in commit
b37747a9
mentioned in commit b37747a92cb498d446b77bcb0a3382efcb84a6eb
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment