extra data for breminale

This commit is contained in:
Martin Geno 2016-06-19 00:01:12 +02:00
parent 5b26b6bf88
commit 4da0b97f38
6 changed files with 61 additions and 41 deletions

View File

@ -32,9 +32,10 @@ func NewAliases(config *models.Config, router *httprouter.Router, prefix string,
func (api *ApiAliases) cleaner() {
for key, alias := range api.aliases.List {
if node := api.nodes.List[key]; node != nil {
//counter for the diffrent attribute
count := 0
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
//counter for the diffrent attribute
count := 3
count += 3
if alias.Hostname == nodeinfo.Hostname {
count -= 1
}
@ -46,25 +47,31 @@ func (api *ApiAliases) cleaner() {
count -= 1
}
}
/*
if alias.Freq24.TxPower == nodeinfo.Freq24.TxPower {
count -= 1
if nodeinfo.Settings != nil {
if nodeinfo.Settings.Freq24 != nil {
count += 2
if alias.Freq24.TxPower == nodeinfo.Settings.Freq24.TxPower {
count -= 1
}
if alias.Freq24.Channel == nodeinfo.Settings.Freq24.Channel {
count -= 1
}
}
if alias.Freq24.Channel == nodeinfo.Freq24.Channel {
count -= 1
if nodeinfo.Settings.Freq5 != nil {
count += 2
if alias.Freq5.TxPower == nodeinfo.Settings.Freq5.TxPower {
count -= 1
}
if alias.Freq5.Channel == nodeinfo.Settings.Freq5.Channel {
count -= 1
}
}
if alias.Freq5.TxPower == nodeinfo.Freq5.TxPower {
count -= 1
}
if alias.Freq5.Channel == nodeinfo.Freq5.Channel {
count -= 1
}
*/
//delete element
if count <= 0 {
delete(api.aliases.List, key)
}
}
//delete element
if count <= 0 {
delete(api.aliases.List, key)
}
}
}
}

14
data/breminale.go Normal file
View File

@ -0,0 +1,14 @@
package data
type Frequence struct {
TxPower uint32 `json:"txpower"`
Channel uint32 `json:"channel"`
}
type Settings struct {
Freq24 *Frequence `json:"freq24,omitempty"`
Freq5 *Frequence `json:"freq5,omitempty"`
}
type SwitchPort struct {
Speed uint32 `json:"speed"`
}

View File

@ -10,6 +10,7 @@ type NodeInfo struct {
Software Software `json:"software"`
Hardware Hardware `json:"hardware"`
VPN bool `json:"vpn"`
Settings *Settings `json:"settings,omitempty"`
}
type BatInterface struct {
Interfaces struct {
@ -20,10 +21,10 @@ type BatInterface struct {
}
type Network struct {
Mac string `json:"mac"`
Addresses []string `json:"addresses"`
Mesh map[string]*BatInterface `json:"mesh"`
MeshInterfaces []string `json:"mesh_interfaces"`
Mac string `json:"mac"`
Addresses []string `json:"addresses"`
Mesh map[string]*BatInterface `json:"mesh"`
MeshInterfaces []string `json:"mesh_interfaces"`
}
type Owner struct {

View File

@ -8,16 +8,16 @@ package data
type Statistics struct {
NodeId string `json:"node_id"`
Clients Clients `json:"clients"`
RootFsUsage float64 `json:"rootfs_usage,omitempty""`
LoadAverage float64 `json:"loadavg,omitempty""`
Memory Memory `json:"memory,omitempty""`
Uptime float64 `json:"uptime,omitempty""`
Idletime float64 `json:"idletime,omitempty""`
Gateway string `json:"gateway,omitempty""`
RootFsUsage float64 `json:"rootfs_usage,omitempty"`
LoadAverage float64 `json:"loadavg,omitempty"`
Memory Memory `json:"memory,omitempty"`
Uptime float64 `json:"uptime,omitempty"`
Idletime float64 `json:"idletime,omitempty"`
Gateway string `json:"gateway,omitempty"`
Processes struct {
Total uint32 `json:"total"`
Running uint32 `json:"running"`
} `json:"processes,omitempty""`
} `json:"processes,omitempty"`
MeshVpn *MeshVPN `json:"mesh_vpn,omitempty"`
Traffic struct {
Tx *Traffic `json:"tx"`
@ -25,7 +25,8 @@ type Statistics struct {
Forward *Traffic `json:"forward"`
MgmtTx *Traffic `json:"mgmt_tx"`
MgmtRx *Traffic `json:"mgmt_rx"`
} `json:"traffic,omitempty""`
} `json:"traffic,omitempty"`
Switch map[string]*SwitchPort `json:"switch,omitempty"`
}
type MeshVPNPeerLink struct {

View File

@ -11,14 +11,10 @@ import (
)
type Alias struct {
Hostname string `json:"hostname,omitempty"`
Location *data.Location `json:"location,omitempty"`
Freq24 *Frequence `json:"freq24,omitempty"`
Freq5 *Frequence `json:"freq5,omitempty"`
}
type Frequence struct {
TxPower int `json:"txpower,omitempty"`
Channel int `json:"channel,omitempty"`
Hostname string `json:"hostname,omitempty"`
Location *data.Location `json:"location,omitempty"`
Freq24 *data.Frequence `json:"freq24,omitempty"`
Freq5 *data.Frequence `json:"freq5,omitempty"`
}
// Nodes struct: cache DB of Node's structs

View File

@ -9,16 +9,17 @@ type Ansible struct {
type AnsibleHostVars struct {
Address string `json:"ansible_ssh_host"`
Hostname string `json:"node_name,omitempty"`
Channel24 int `json:"radio24_channel,omitempty"`
TxPower24 int `json:"radio24_txpower,omitempty"`
Channel5 int `json:"radio5_channel,omitempty"`
TxPower5 int `json:"radio5_txpower,omitempty"`
Channel24 uint32 `json:"radio24_channel,omitempty"`
TxPower24 uint32 `json:"radio24_txpower,omitempty"`
Channel5 uint32 `json:"radio5_channel,omitempty"`
TxPower5 uint32 `json:"radio5_txpower,omitempty"`
GeoLatitude float64 `json:"geo_latitude,omitempty"`
GeoLongitude float64 `json:"geo_longitude,omitempty"`
}
func GenerateAnsible(nodes *Nodes, aliases map[string]*Alias) *Ansible {
ansible := &Ansible{Nodes: make([]string, 0)}
ansible.Meta.HostVars = make(map[string]*AnsibleHostVars)
for nodeid, alias := range aliases {
if node := nodes.List[nodeid]; node != nil {