Skip to content

Commit

Permalink
feat: allow definition of custom autnums
Browse files Browse the repository at this point in the history
Change-Id: I9fe950411d90836f7c0e29e2c952d0dc947d4796
  • Loading branch information
fionera committed Jul 18, 2023
1 parent 95bc29e commit bd84332
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
12 changes: 12 additions & 0 deletions deploy/single-node/config.cue
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ _deviceAddressTest: {
}
}

#UserData: {
// Custom ASNs
autnums: [ASN=string]: {
asn: *strconv.Atoi(ASN) | int
name: string
country: string
}
}

#NetMetaConfig: {
// Allow the use of legacy config parameters
#LegacyNetMetaConfig
Expand Down Expand Up @@ -221,6 +230,9 @@ _deviceAddressTest: {

// Config parameter like interface names. See #SamplerConfig
sampler: #SamplerConfig

// Userprovided data like custom ASNs
userData: #UserData
}

#Image: {
Expand Down
1 change: 1 addition & 0 deletions deploy/single-node/defs.cue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ k8s_list: [
clickhouseReadonlyPassword: netmeta.config.clickhouseReadonlyPassword
enableClickhouseIngress: netmeta.config.enableClickhouseIngress
sampler: netmeta.config.sampler
userData: netmeta.config.userData
}
}),

Expand Down
9 changes: 9 additions & 0 deletions deploy/single-node/k8s/clickhouse/clickhouse.cue
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ import (
...
}

#UserData: {
autnums: [string]: {
asn: int
name: string
country: string
}
}

#Config: {
clickhouseAdminPassword: string
clickhouseReadonlyPassword: string
enableClickhouseIngress: bool
sampler: #SamplerConfig
userData: #UserData
}

ClickHouseInstallation: netmeta: spec: {
Expand Down
56 changes: 56 additions & 0 deletions deploy/single-node/k8s/clickhouse/files.cue
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,31 @@ _files: HostNames: {
}
}

_files: user_autnums: {
data: strings.Join([ for _, e in #Config.userData.autnums {
strings.Join(["\(e.asn)", e.name, e.country], "\t")
}], "\n")

cfg: {
layout: flat: null
structure: [{
id: name: "asnum"
}, {
attribute: {
name: "name"
type: "String"
null_value: null
}
}, {
attribute: {
name: "country"
type: "String"
null_value: null
}
}]
}
}

ClickHouseInstallation: netmeta: spec: configuration: files: "risinfo.conf": (xml.#Marshal & {in: {
yandex: dictionary: {
name: "risinfo"
Expand All @@ -199,6 +224,37 @@ ClickHouseInstallation: netmeta: spec: configuration: files: "risinfo.conf": (xm
ClickHouseInstallation: netmeta: spec: configuration: files: "autnums.conf": (xml.#Marshal & {in: {
yandex: dictionary: {
name: "autnums"
source: clickhouse: {
query:
#"""
SELECT * FROM dictionaries.risinfo_autnums
UNION ALL
SELECT * FROM dictionaries.user_autnums
"""#
}
lifetime: 3600
layout: flat: null
structure: [{
id: name: "asnum"
}, {
attribute: {
name: "name"
type: "String"
null_value: null
}
}, {
attribute: {
name: "country"
type: "String"
null_value: null
}
}]
}
}}).out

ClickHouseInstallation: netmeta: spec: configuration: files: "risinfo_autnums.conf": (xml.#Marshal & {in: {
yandex: dictionary: {
name: "risinfo_autnums"
source: http: {
url: "http://risinfo/autnums.tsv"
format: "TabSeparated"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +goose Up
CREATE DATABASE dictionaries Engine=Dictionary;

-- +goose Down
DROP DATABASE dictionaries;

0 comments on commit bd84332

Please sign in to comment.