Full web : fichiers restants
This commit is contained in:
1 parent
ec3b7c9a01
commit
4826fa5b82
26 files changed
+2537
-793
No files matched your search
+36
-12
@@ -1,7 +1,7 @@
|
||||
// Package demo starts fake PVE clusters (pvetest) and fills a database with
|
||||
// them, to try the web UI without a Proxmox cluster: a reference, two clients
|
||||
// with differences (missing objects, different fields, a missing mapping) and
|
||||
// a PVE 8 cluster that is refused.
|
||||
// Package demo starts fake PVE clusters (pvetest: API and SSH) and fills a
|
||||
// database with them, to try the web UI without a Proxmox cluster: a primary,
|
||||
// two targets with differences (missing objects, different fields, accounts
|
||||
// and passwords, a missing mapping) and a PVE 8 cluster that is refused.
|
||||
package demo
|
||||
|
||||
import (
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"pve-confsync/internal/adapter"
|
||||
"pve-confsync/internal/model"
|
||||
"pve-confsync/internal/pve"
|
||||
"pve-confsync/internal/pve/pvetest"
|
||||
"pve-confsync/internal/store"
|
||||
)
|
||||
@@ -50,6 +51,14 @@ func Start(ctx context.Context, st *store.Store) (*Clusters, error) {
|
||||
"dhcp-range": []any{"start-address=10.1.0.100,end-address=10.1.0.200"}}
|
||||
ref.Pending.Subnets["vlanz-10.2.0.0-24"] = map[string]any{"vnet": "v200", "gateway": "10.2.0.1"}
|
||||
ref.Commit()
|
||||
ref.Groups["admins"] = map[string]any{"comment": "Administrateurs"}
|
||||
ref.Groups["ops"] = map[string]any{"comment": "Exploitation"}
|
||||
ref.Roles["ConfSyncOps"] = "Sys.Audit,VM.Audit,VM.PowerMgmt"
|
||||
ref.Users["alice@pve"] = map[string]any{"enable": 1, "firstname": "Alice", "email": "alice@example.org", "groups": "admins"}
|
||||
ref.Users["bob@pve"] = map[string]any{"enable": 1, "firstname": "Bob", "email": "bob@example.org", "groups": "ops", "expire": 1893456000}
|
||||
ref.Users["carol@pam"] = map[string]any{"enable": 1, "comment": "compte Linux, non répliqué"}
|
||||
ref.Shadow["alice"] = "$5$Kd1Xa9$Q8yJdemoAliceHashOnlyForTheDemo0123456789AB"
|
||||
ref.Shadow["bob"] = "$5$Pq7Zr2$W3vLdemoBobHashOnlyForTheDemo0123456789ABCDE"
|
||||
|
||||
// site-a: tags and an MTU behind, the VXLAN zone and the dev network missing
|
||||
a := pvetest.New("9.0.10")
|
||||
@@ -65,6 +74,9 @@ func Start(ctx context.Context, st *store.Store) (*Clusters, error) {
|
||||
a.Pending.VNets["ceph"] = map[string]any{"zone": "stor", "tag": 50, "alias": "ceph public"}
|
||||
a.Pending.Subnets["vlanz-10.1.0.0-24"] = map[string]any{"vnet": "v100", "gateway": "10.1.0.254"}
|
||||
a.Commit()
|
||||
a.Groups["admins"] = map[string]any{"comment": "Admins"}
|
||||
a.Users["alice@pve"] = map[string]any{"enable": 1, "firstname": "Alice", "email": "alice@old.example.org", "groups": "admins"}
|
||||
a.Shadow["alice"] = "$5$OldOld$oldAliceHashOnSiteA0123456789ABCDEFGHIJKLMNOP"
|
||||
|
||||
// site-b: nearly in line, but no mapping for the bridge of the "stor" zone
|
||||
// (blocking error) and a local zone absent from the reference (kept, no prune)
|
||||
@@ -84,21 +96,33 @@ func Start(ctx context.Context, st *store.Store) (*Clusters, error) {
|
||||
"dhcp-range": []any{"start-address=10.1.0.100,end-address=10.1.0.200"}}
|
||||
b.Pending.Subnets["vlanz-10.2.0.0-24"] = map[string]any{"vnet": "v200", "gateway": "10.2.0.1"}
|
||||
b.Commit()
|
||||
b.Groups["admins"] = map[string]any{"comment": "Administrateurs"}
|
||||
b.Groups["ops"] = map[string]any{"comment": "Exploitation"}
|
||||
b.Roles["ConfSyncOps"] = "Sys.Audit,VM.Audit,VM.PowerMgmt"
|
||||
b.Users["alice@pve"] = map[string]any{"enable": 1, "firstname": "Alice", "email": "alice@example.org", "groups": "admins"}
|
||||
b.Users["bob@pve"] = map[string]any{"enable": 1, "firstname": "Bob", "email": "bob@example.org", "groups": "ops", "expire": 1893456000}
|
||||
b.Shadow["alice"] = ref.Shadow["alice"]
|
||||
b.Shadow["bob"] = ref.Shadow["bob"]
|
||||
|
||||
// legacy: PVE 8, refused by the version check
|
||||
old := pvetest.New("8.4.1")
|
||||
|
||||
c := &Clusters{servers: []*pvetest.Server{ref, a, b, old}}
|
||||
save := func(s *pvetest.Server, name, token string, refer bool, pos int,
|
||||
save := func(s *pvetest.Server, name, role string, pos int,
|
||||
mapping map[model.Kind]map[string]map[string]any, pol map[model.Kind]map[string]adapter.Policy) error {
|
||||
sum := sha256.Sum256(s.Certificate().Raw)
|
||||
return st.SaveCluster(ctx, "", store.Cluster{Name: name, Reference: refer, Position: pos, URL: s.URL,
|
||||
TokenID: token, Secret: "demo-" + name, Fingerprint: hex.EncodeToString(sum[:]),
|
||||
Mapping: mapping, Policies: pol})
|
||||
host, port := s.SSHAddr()
|
||||
err := st.SaveCluster(ctx, "", store.Cluster{Name: name, Role: role, Position: pos, URL: s.URL,
|
||||
User: "root@pam", Password: pvetest.Password, TLS: store.TLSPin, Fingerprint: pve.FormatFingerprint(hex.EncodeToString(sum[:])),
|
||||
SSHHost: host, SSHPort: port, Mapping: mapping, Policies: pol})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return st.Pin(ctx, name, "", s.SSHHostKey(), nil)
|
||||
}
|
||||
steps := []error{
|
||||
save(ref, "ref-rennes", "confsync@pve!ro", true, 0, nil, nil),
|
||||
save(a, "site-a", "confsync@pve!rw", false, 1, map[model.Kind]map[string]map[string]any{
|
||||
save(ref, "pve-rennes", store.ClusterPrimary, 0, nil, nil),
|
||||
save(a, "site-a", store.ClusterTarget, 1, map[model.Kind]map[string]map[string]any{
|
||||
model.KindDatacenter: {"datacenter": {"next-id": "lower=2000,upper=2999"}},
|
||||
model.KindZone: {
|
||||
"vlanz": {"bridge": "vmbr1"},
|
||||
@@ -106,13 +130,13 @@ func Start(ctx context.Context, st *store.Store) (*Clusters, error) {
|
||||
"vxz": {"peers": "192.168.10.1,192.168.10.2"},
|
||||
},
|
||||
}, nil),
|
||||
save(b, "site-b", "confsync@pve!rw", false, 2, map[model.Kind]map[string]map[string]any{
|
||||
save(b, "site-b", store.ClusterTarget, 2, map[model.Kind]map[string]map[string]any{
|
||||
model.KindZone: {
|
||||
"vlanz": {"bridge": "vmbr0"},
|
||||
"vxz": {"peers": "172.16.0.1,172.16.0.2"},
|
||||
},
|
||||
}, map[model.Kind]map[string]adapter.Policy{model.KindZone: {"mtu": adapter.Ignore}}),
|
||||
save(old, "legacy-pve8", "confsync@pve!rw", false, 3, nil, nil),
|
||||
save(old, "legacy-pve8", store.ClusterTarget, 3, nil, nil),
|
||||
st.SaveSettings(ctx, store.Settings{Kinds: model.Kinds,
|
||||
Policies: map[model.Kind]map[string]adapter.Policy{model.KindDatacenter: {"keyboard": adapter.Sync}}}),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user