matches with the full path of the container
This commit is contained in:
parent
99d2c31f4d
commit
4c740cbc54
@ -1,18 +0,0 @@
|
|||||||
package raw
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestUnmarshal(t *testing.T) {
|
|
||||||
cDesc, err := Unmarshal("test_resources/cdesc.json")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Error in unmarshalling: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cDesc.All_hosts[0].NetworkInterface.VethHost != "veth24031eth1" &&
|
|
||||||
cDesc.All_hosts[0].NetworkInterface.VethChild != "eth1" {
|
|
||||||
t.Errorf("Cannot find network interface in %s", cDesc)
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,27 +23,29 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
var argContainerHints = flag.String("container_hints", "/etc/cadvisor/container_description.json", "container hints file")
|
var argContainerHints = flag.String("container_hints", "/etc/cadvisor/container_hints.json", "container hints file")
|
||||||
type containerHints struct {
|
type containerHints struct {
|
||||||
All_hosts []containerHint `json:"all_hosts,omitempty"`
|
AllHosts []containerHint `json:"all_hosts,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type containerHint struct {
|
type containerHint struct {
|
||||||
Id string `json:"id,omitempty"`
|
FullPath string `json:"full_path,omitempty"`
|
||||||
NetworkInterface *networkInterface `json:"network_interface,omitempty"`
|
NetworkInterface *networkInterface `json:"network_interface,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type networkInterface struct {
|
type networkInterface struct {
|
||||||
VethHost string `json:"VethHost,omitempty"`
|
VethHost string `json:"veth_host,omitempty"`
|
||||||
VethChild string `json:"VethChild,omitempty"`
|
VethChild string `json:"veth_child,omitempty"`
|
||||||
NsPath string `json:"NsPath,omitempty"`
|
NsPath string `json:"ns_path,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Unmarshal(containerHintsFile string) (containerHints, error) {
|
func getContainerHintsFromFile(containerHintsFile string) (containerHints, error) {
|
||||||
dat, err := ioutil.ReadFile(containerHintsFile)
|
dat, err := ioutil.ReadFile(containerHintsFile)
|
||||||
var cDesc containerHints
|
|
||||||
|
var cHints containerHints
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = json.Unmarshal(dat, &cDesc)
|
err = json.Unmarshal(dat, &cHints)
|
||||||
}
|
}
|
||||||
return cDesc, err
|
|
||||||
|
return cHints, err
|
||||||
}
|
}
|
18
container/raw/container_hints_test.go
Normal file
18
container/raw/container_hints_test.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package raw
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUnmarshal(t *testing.T) {
|
||||||
|
cHints, err := getContainerHintsFromFile("test_resources/container_hints.json")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error in unmarshalling: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cHints.AllHosts[0].NetworkInterface.VethHost != "veth24031eth1" &&
|
||||||
|
cHints.AllHosts[0].NetworkInterface.VethChild != "eth1" {
|
||||||
|
t.Errorf("Cannot find network interface in %s", cHints)
|
||||||
|
}
|
||||||
|
}
|
@ -52,20 +52,16 @@ func newRawContainerHandler(name string, cgroupSubsystems *cgroupSubsystems, mac
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cDesc, err := Unmarshal(*argContainerHints)
|
cHints, err := getContainerHintsFromFile(*argContainerHints)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
glog.Fatalf("Error unmarshalling json %s Error: %s", *argContainerHints, err)
|
||||||
}
|
}
|
||||||
var networkInterface *networkInterface
|
var networkInterface *networkInterface
|
||||||
for _, container := range cDesc.All_hosts {
|
for _, container := range cHints.AllHosts {
|
||||||
var cName string
|
if !strings.Contains(container.FullPath, "/") {
|
||||||
if strings.Contains(container.Id, "/") {
|
glog.Fatalf("Invalid container fullPath %s", container.FullPath)
|
||||||
cName = name
|
|
||||||
} else {
|
|
||||||
names := strings.SplitAfter(name, "/")
|
|
||||||
cName = names[len(names)-1]
|
|
||||||
}
|
}
|
||||||
if cName == container.Id {
|
if name == container.FullPath {
|
||||||
networkInterface = container.NetworkInterface
|
networkInterface = container.NetworkInterface
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "Container specification",
|
"name": "Container Hints",
|
||||||
"description": "Container specification",
|
"description": "Container hints file",
|
||||||
"all_hosts": [
|
"all_hosts": [
|
||||||
{
|
{
|
||||||
"name": "10-10-10-27",
|
|
||||||
"ip": "10.10.10.27/24",
|
|
||||||
"publish": null,
|
|
||||||
"gateway": null,
|
|
||||||
"hostname": "10-10-10-27.local.altiscale.com",
|
|
||||||
"privileged": "true",
|
|
||||||
"init": null,
|
|
||||||
"cpu": null,
|
|
||||||
"memory": null,
|
|
||||||
"net": null,
|
|
||||||
"netinit": "false",
|
|
||||||
"network_interface": {
|
"network_interface": {
|
||||||
"VethChild": "eth1",
|
"veth_child": "eth1",
|
||||||
"VethHost": "veth24031eth1"
|
"veth_host": "veth24031eth1"
|
||||||
},
|
},
|
||||||
"mounts": [
|
"mounts": [
|
||||||
{
|
{
|
||||||
@ -45,7 +34,7 @@
|
|||||||
"permission": "rw"
|
"permission": "rw"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"id": "18a4585950db428e4d5a65c216a5d708d241254709626f4cb300ee963fb4b144"
|
"full_path": "18a4585950db428e4d5a65c216a5d708d241254709626f4cb300ee963fb4b144"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user