Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
runtopo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
hdacloud
runtopo
Commits
176d98c2
Commit
176d98c2
authored
4 years ago
by
Lars Seipel
Browse files
Options
Downloads
Patches
Plain Diff
runner/libvirt: on the mgmt server, include devices in /etc/hosts
parent
16ee2c1c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
runner/libvirt/customize.go
+22
-10
22 additions, 10 deletions
runner/libvirt/customize.go
runner/libvirt/libvirt_test.go
+1
-1
1 addition, 1 deletion
runner/libvirt/libvirt_test.go
runner/libvirt/runner.go
+6
-5
6 additions, 5 deletions
runner/libvirt/runner.go
with
29 additions
and
16 deletions
runner/libvirt/customize.go
+
22
−
10
View file @
176d98c2
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"context"
"context"
"fmt"
"fmt"
"io"
"io"
"net"
"os/exec"
"os/exec"
"strings"
"strings"
...
@@ -172,14 +173,14 @@ func writeExtraMgmtServerCommands(w io.Writer, d *device) {
...
@@ -172,14 +173,14 @@ func writeExtraMgmtServerCommands(w io.Writer, d *device) {
io
.
WriteString
(
w
,
"run-command systemctl enable dnsmasq.service
\n
"
)
io
.
WriteString
(
w
,
"run-command systemctl enable dnsmasq.service
\n
"
)
}
}
func
generateHostsFile
(
ctx
context
.
Context
,
r
*
Runner
,
t
*
topology
.
T
)
(
file
[]
byte
,
err
error
)
{
type
etherHost
struct
{
defer
func
()
{
name
string
if
err
!=
nil
{
ip
*
net
.
IPAddr
err
=
fmt
.
Errorf
(
"generateHostsFile: %w"
,
err
)
mac
net
.
HardwareAddr
}
}
}()
var
buf
bytes
.
Buffer
func
gatherHosts
(
ctx
context
.
Context
,
r
*
Runner
,
t
*
topology
.
T
)
[]
etherHost
{
var
hosts
[]
etherHost
for
name
,
d
:=
range
r
.
devices
{
for
name
,
d
:=
range
r
.
devices
{
if
name
==
"oob-mgmt-server"
||
name
==
"oob-mgmt-switch"
{
if
name
==
"oob-mgmt-server"
||
name
==
"oob-mgmt-switch"
{
continue
continue
...
@@ -193,9 +194,20 @@ func generateHostsFile(ctx context.Context, r *Runner, t *topology.T) (file []by
...
@@ -193,9 +194,20 @@ func generateHostsFile(ctx context.Context, r *Runner, t *topology.T) (file []by
if
mgmtIP
==
nil
{
if
mgmtIP
==
nil
{
continue
continue
}
}
fmt
.
Fprintf
(
&
buf
,
"%s,%s,%s
\n
"
,
eth0
.
mac
,
mgmtIP
,
name
)
hosts
=
append
(
hosts
,
etherHost
{
name
:
name
,
ip
:
mgmtIP
,
mac
:
eth0
.
mac
,
})
}
}
return
buf
.
Bytes
(),
nil
return
hosts
}
func
generateDnsmasqHostsFile
(
hosts
[]
etherHost
)
[]
byte
{
var
buf
bytes
.
Buffer
for
_
,
h
:=
range
hosts
{
fmt
.
Fprintf
(
&
buf
,
"%s,%s,%s
\n
"
,
h
.
mac
,
h
.
ip
,
h
.
name
)
}
return
buf
.
Bytes
()
}
}
This diff is collapsed.
Click to expand it.
runner/libvirt/libvirt_test.go
+
1
−
1
View file @
176d98c2
...
@@ -52,7 +52,7 @@ func TestDnsmasqHostsFile(t *testing.T) {
...
@@ -52,7 +52,7 @@ func TestDnsmasqHostsFile(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
content
,
err
:=
generateHostsFile
(
ctx
,
r
,
topo
)
content
:=
generate
Dnsmasq
HostsFile
(
gatherHosts
(
ctx
,
r
,
topo
)
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
runner/libvirt/runner.go
+
6
−
5
View file @
176d98c2
...
@@ -525,13 +525,14 @@ func (r *Runner) customizeDomains(ctx context.Context, t *topology.T) (err error
...
@@ -525,13 +525,14 @@ func (r *Runner) customizeDomains(ctx context.Context, t *topology.T) (err error
fmt
.
Fprintf
(
&
buf
,
"ssh-inject %s:string:%s
\n
"
,
user
,
k
)
fmt
.
Fprintf
(
&
buf
,
"ssh-inject %s:string:%s
\n
"
,
user
,
k
)
}
}
if
d
.
topoDev
.
Function
()
==
topology
.
FunctionOOBServer
{
if
d
.
topoDev
.
Function
()
==
topology
.
FunctionOOBServer
{
hosts
Bytes
,
err1
:=
generate
Hosts
File
(
ctx
,
r
,
t
)
hosts
:=
gather
Hosts
(
ctx
,
r
,
t
)
if
err
!=
nil
{
for
_
,
h
:=
range
hosts
{
err
=
err1
fmt
.
Fprintf
(
&
buf
,
"append-line /etc/hosts:%s %s
\n
"
,
break
h
.
ip
,
h
.
name
)
}
}
dnsmasqHosts
:=
generateDnsmasqHostsFile
(
hosts
)
fmt
.
Fprintf
(
&
buf
,
"write /etc/dnsmasq.hostsfile:%s
\n
"
,
fmt
.
Fprintf
(
&
buf
,
"write /etc/dnsmasq.hostsfile:%s
\n
"
,
bytes
.
Replace
(
hostsByte
s
,
[]
byte
(
"
\n
"
),
bytes
.
Replace
(
dnsmasqHost
s
,
[]
byte
(
"
\n
"
),
[]
byte
(
"
\\\n
"
),
-
1
))
[]
byte
(
"
\\\n
"
),
-
1
))
}
}
extra
:=
strings
.
NewReader
(
buf
.
String
())
extra
:=
strings
.
NewReader
(
buf
.
String
())
...
...
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