Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
float
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
ai3
float
Commits
85fa23db
Commit
85fa23db
authored
6 months ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Distribute updated copy of floatup
parent
a1ae34af
No related branches found
No related tags found
1 merge request
!304
Fix CI issues with vmine / floatup
Pipeline
#77527
passed
6 months ago
Stage: test
Stage: cleanup
Changes
1
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/floatup.py
+42
-47
42 additions, 47 deletions
scripts/floatup.py
with
42 additions
and
47 deletions
scripts/floatup.py
+
42
−
47
View file @
85fa23db
...
@@ -15,37 +15,6 @@ import yaml
...
@@ -15,37 +15,6 @@ import yaml
import
zlib
import
zlib
# The Vagrant "insecure" SSH key that is used to log onto the VMs.
INSECURE_PRIVATE_KEY
=
'''
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI
w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP
kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2
hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NO
Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW
yLbIbEgE98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sz+xT2axM0/W/CRknmGaJ
kda/AoGANWrLCz708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH
+vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ
NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s=
-----END RSA PRIVATE KEY-----
'''
def
parse_inventory
(
path
,
host_attrs
):
def
parse_inventory
(
path
,
host_attrs
):
with
open
(
path
)
as
fd
:
with
open
(
path
)
as
fd
:
inventory
=
yaml
.
safe_load
(
fd
)
inventory
=
yaml
.
safe_load
(
fd
)
...
@@ -87,16 +56,24 @@ def encode_dashboard_request(req):
...
@@ -87,16 +56,24 @@ def encode_dashboard_request(req):
return
base64
.
urlsafe_b64encode
(
comp
.
flush
()).
decode
(
'
ascii
'
)
return
base64
.
urlsafe_b64encode
(
comp
.
flush
()).
decode
(
'
ascii
'
)
def
install_vagrant_ssh_key
():
def
generate_ssh_key
():
# Install the SSH key as Vagrant would do, for compatibility.
path
=
'
/root/.ssh/temp
'
key_path
=
os
.
path
.
join
(
if
os
.
getenv
(
'
HOME
'
):
os
.
getenv
(
'
HOME
'
),
'
.vagrant.d
'
,
'
insecure_private_key
'
)
path
=
os
.
getenv
(
'
HOME
'
)
+
'
/.ssh/temp
'
if
os
.
path
.
exists
(
key_path
):
os
.
makedirs
(
os
.
path
.
dirname
(
path
),
mode
=
0o700
,
exist_ok
=
True
)
return
subprocess
.
check_call
([
'
ssh-keygen
'
,
'
-t
'
,
'
ed25519
'
,
'
-f
'
,
path
,
'
-C
'
,
''
,
'
-N
'
,
''
])
os
.
makedirs
(
os
.
path
.
dirname
(
key_path
),
mode
=
0o700
,
exist_ok
=
True
)
return
path
with
open
(
key_path
,
'
w
'
)
as
fd
:
fd
.
write
(
INSECURE_PRIVATE_KEY
)
os
.
chmod
(
key_path
,
0o600
)
def
generate_ssh_config
(
inventory
,
private_key_path
):
netglob
=
re
.
sub
(
r
'
\.0/24$
'
,
'
.*
'
,
inventory
[
'
network
'
])
return
f
'''
Host
{
netglob
}
User root
IdentityFile
{
private_key_path
}
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
'''
def
main
():
def
main
():
...
@@ -135,8 +112,11 @@ def main():
...
@@ -135,8 +112,11 @@ def main():
help
=
'
vmine dashboard base URL (for Gitlab CI)
'
)
help
=
'
vmine dashboard base URL (for Gitlab CI)
'
)
parser
.
add_argument
(
parser
.
add_argument
(
'
--ssh-key
'
,
metavar
=
'
FILE
'
,
'
--ssh-key
'
,
metavar
=
'
FILE
'
,
type
=
argparse
.
FileType
(
'
r
'
),
help
=
'
root SSH key to install on VMs
'
)
help
=
'
root SSH key to install on VMs
'
)
parser
.
add_argument
(
'
--ssh-config
'
,
metavar
=
'
FILE
'
,
default
=
'
/root/.ssh/config
'
,
help
=
'
append SSH config to this file
'
)
parser
.
add_argument
(
parser
.
add_argument
(
'
--name
'
,
metavar
=
'
NAME
'
,
'
--name
'
,
metavar
=
'
NAME
'
,
help
=
'
group name (for named groups)
'
)
help
=
'
group name (for named groups)
'
)
...
@@ -153,14 +133,19 @@ def main():
...
@@ -153,14 +133,19 @@ def main():
host_attrs
[
'
cpu
'
]
=
args
.
cpu
host_attrs
[
'
cpu
'
]
=
args
.
cpu
if
args
.
image
:
if
args
.
image
:
host_attrs
[
'
image
'
]
=
args
.
image
host_attrs
[
'
image
'
]
=
args
.
image
req
=
parse_inventory
(
args
.
inventory
,
host_attrs
)
req
=
parse_inventory
(
args
.
inventory
,
host_attrs
)
req
[
'
ttl
'
]
=
args
.
ttl
req
[
'
ttl
'
]
=
args
.
ttl
if
args
.
name
:
if
args
.
name
:
req
[
'
name
'
]
=
args
.
name
req
[
'
name
'
]
=
args
.
name
if
args
.
ssh_key
:
if
args
.
ssh_key
:
req
[
'
ssh_key
'
]
=
args
.
ssh_key
ssh_key
_path
=
args
.
ssh_key
else
:
else
:
install_vagrant_ssh_key
()
ssh_key_path
=
generate_ssh_key
()
with
open
(
ssh_key_path
+
'
.pub
'
,
'
r
'
)
as
fd
:
req
[
'
ssh_key
'
]
=
fd
.
read
().
strip
()
os
.
umask
(
0o077
)
print
(
f
'
creating VM group with attrs
{
host_attrs
}
...
'
)
print
(
f
'
creating VM group with attrs
{
host_attrs
}
...
'
)
print
(
f
'
vmine request:
{
req
}
'
)
print
(
f
'
vmine request:
{
req
}
'
)
...
@@ -170,13 +155,20 @@ def main():
...
@@ -170,13 +155,20 @@ def main():
fd
.
write
(
group_id
)
fd
.
write
(
group_id
)
print
(
f
'
created VM group
{
group_id
}
'
)
print
(
f
'
created VM group
{
group_id
}
'
)
if
args
.
ssh_config
:
print
(
f
'
updating ssh config
'
)
with
open
(
args
.
ssh_config
,
'
a
'
)
as
fd
:
fd
.
write
(
generate_ssh_config
(
req
,
ssh_key_path
))
if
args
.
env
:
if
args
.
env
:
with
open
(
args
.
env
,
'
w
'
)
as
fd
:
with
open
(
args
.
env
,
'
w
'
)
as
fd
:
fd
.
write
(
f
'
VMINE_ID=
{
group_id
}
\n
'
)
fd
.
write
(
f
'
VMINE_ID=
{
group_id
}
\n
'
)
if
args
.
dashboard_url
:
if
args
.
dashboard_url
:
base_url
=
args
.
dashboard_url
.
rstrip
(
'
/
'
)
base_url
=
args
.
dashboard_url
.
rstrip
(
'
/
'
)
payload
=
encode_dashboard_request
(
req
)
payload
=
encode_dashboard_request
(
req
)
fd
.
write
(
f
'
VMINE_GROUP_URL=
{
base_url
}
/dash/
{
payload
}
\n
'
)
dashboard_url
=
f
'
{
base_url
}
/dash/
{
payload
}
'
fd
.
write
(
f
'
VMINE_GROUP_URL=
{
dashboard_url
}
\n
'
)
print
(
f
'
dashboard URL:
{
dashboard_url
}
'
)
elif
args
.
cmd
==
'
down
'
:
elif
args
.
cmd
==
'
down
'
:
req
=
{}
req
=
{}
...
@@ -192,8 +184,11 @@ def main():
...
@@ -192,8 +184,11 @@ def main():
return
return
req
[
'
group_id
'
]
=
group_id
req
[
'
group_id
'
]
=
group_id
print
(
f
'
stopping VM group
{
group_id
}
...
'
)
print
(
f
'
stopping VM group
{
group_id
}
...
'
)
try
:
do_request
(
args
.
url
+
'
/api/stop-group
'
,
args
.
ssh
,
req
)
do_request
(
args
.
url
+
'
/api/stop-group
'
,
args
.
ssh
,
req
)
if
args
.
state_file
:
except
:
pass
if
args
.
state_file
and
os
.
path
.
exists
(
args
.
state_file
):
os
.
remove
(
args
.
state_file
)
os
.
remove
(
args
.
state_file
)
...
...
This diff is collapsed.
Click to expand it.
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