mirror of
https://github.com/hanzozt/zt.git
synced 2026-11-02 11:38:22 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
217 lines
5.8 KiB
Go
217 lines
5.8 KiB
Go
/*
|
|
(c) Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"embed"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/michaelquigley/pfxlog"
|
|
"github.com/hanzozt/fablab"
|
|
"github.com/hanzozt/fablab/kernel/lib/actions/component"
|
|
"github.com/hanzozt/fablab/kernel/lib/binding"
|
|
"github.com/hanzozt/fablab/kernel/lib/runlevel/0_infrastructure/aws_ssh_key"
|
|
semaphore0 "github.com/hanzozt/fablab/kernel/lib/runlevel/0_infrastructure/semaphore"
|
|
terraform_0 "github.com/hanzozt/fablab/kernel/lib/runlevel/0_infrastructure/terraform"
|
|
distribution "github.com/hanzozt/fablab/kernel/lib/runlevel/3_distribution"
|
|
"github.com/hanzozt/fablab/kernel/lib/runlevel/3_distribution/rsync"
|
|
fablib_5_operation "github.com/hanzozt/fablab/kernel/lib/runlevel/5_operation"
|
|
aws_ssh_key2 "github.com/hanzozt/fablab/kernel/lib/runlevel/6_disposal/aws_ssh_key"
|
|
"github.com/hanzozt/fablab/kernel/lib/runlevel/6_disposal/terraform"
|
|
"github.com/hanzozt/fablab/kernel/model"
|
|
"github.com/hanzozt/fablab/resources"
|
|
"github.com/hanzozt/zt/zttest/models/dtls/actions"
|
|
"github.com/hanzozt/zt/zttest/models/test_resources"
|
|
"github.com/hanzozt/zt/zttest/ztlab"
|
|
"github.com/hanzozt/zt/zttest/ztlab/actions/edge"
|
|
"github.com/hanzozt/zt/zttest/ztlab/models"
|
|
ztlib_5_operation "github.com/hanzozt/zt/zttest/ztlab/runlevel/5_operation"
|
|
)
|
|
|
|
//go:embed configs
|
|
var configResource embed.FS
|
|
|
|
func getUniqueId() string {
|
|
if runId := os.Getenv("GITHUB_RUN_ID"); runId != "" {
|
|
return "-" + runId + "." + os.Getenv("GITHUB_RUN_ATTEMPT")
|
|
}
|
|
return "-" + os.Getenv("USER")
|
|
}
|
|
|
|
var Model = &model.Model{
|
|
Id: "dtls",
|
|
Scope: model.Scope{
|
|
Defaults: model.Variables{
|
|
"environment": "dtls" + getUniqueId(),
|
|
"credentials": model.Variables{
|
|
"aws": model.Variables{
|
|
"managed_key": true,
|
|
},
|
|
"ssh": model.Variables{
|
|
"username": "ubuntu",
|
|
},
|
|
"edge": model.Variables{
|
|
"username": "admin",
|
|
"password": "admin",
|
|
},
|
|
},
|
|
"metrics": model.Variables{
|
|
"influxdb": model.Variables{
|
|
"url": "http://localhost:8086",
|
|
"db": "zt",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
Factories: []model.Factory{
|
|
model.FactoryFunc(func(m *model.Model) error {
|
|
pfxlog.Logger().Infof("environment [%s]", m.MustStringVariable("environment"))
|
|
m.AddActivationActions("stop", "bootstrap", "start")
|
|
return nil
|
|
}),
|
|
model.FactoryFunc(func(m *model.Model) error {
|
|
return m.ForEachHost("*", 1, func(host *model.Host) error {
|
|
host.InstanceType = "t2.micro"
|
|
return nil
|
|
})
|
|
}),
|
|
model.FactoryFunc(func(m *model.Model) error {
|
|
return m.ForEachHost("component.edge-router", 1, func(host *model.Host) error {
|
|
host.InstanceType = "c5.xlarge"
|
|
return nil
|
|
})
|
|
}),
|
|
//model.FactoryFunc(func(m *model.Model) error {
|
|
// return m.ForEachComponent(".edge-router", 1, func(c *model.Component) error {
|
|
// c.Type.(*ztlab.RouterType).Version = "v1.1.11"
|
|
// return nil
|
|
// })
|
|
//}),
|
|
},
|
|
|
|
Resources: model.Resources{
|
|
resources.Configs: resources.SubFolder(configResource, "configs"),
|
|
resources.Terraform: test_resources.TerraformResources(),
|
|
},
|
|
|
|
Regions: model.Regions{
|
|
"us-east-1": {
|
|
Region: "us-east-1",
|
|
Site: "us-east-1a",
|
|
Hosts: model.Hosts{
|
|
"ctrl": {
|
|
Components: model.Components{
|
|
"ctrl": {
|
|
Scope: model.Scope{Tags: model.Tags{"ctrl"}},
|
|
Type: &ztlab.ControllerType{},
|
|
},
|
|
},
|
|
},
|
|
"router-client": {
|
|
Scope: model.Scope{Tags: model.Tags{"ert-client"}},
|
|
Components: model.Components{
|
|
"router-client": {
|
|
Scope: model.Scope{Tags: model.Tags{"edge-router", "terminator", "tunneler", "client"}},
|
|
Type: &ztlab.RouterType{
|
|
Debug: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"us-west-2": {
|
|
Region: "us-west-2",
|
|
Site: "us-west-2b",
|
|
Hosts: model.Hosts{
|
|
"router-host": {
|
|
Components: model.Components{
|
|
"router-host": {
|
|
Scope: model.Scope{Tags: model.Tags{"edge-router", "tunneler", "host", "ert-host"}},
|
|
Type: &ztlab.RouterType{
|
|
Debug: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
Actions: model.ActionBinders{
|
|
"bootstrap": actions.NewBootstrapAction(),
|
|
"start": actions.NewStartAction(),
|
|
"stop": model.Bind(component.StopInParallel("*", 15)),
|
|
"login": model.Bind(edge.Login("#ctrl")),
|
|
},
|
|
|
|
Infrastructure: model.Stages{
|
|
aws_ssh_key.Express(),
|
|
&terraform_0.Terraform{
|
|
Retries: 3,
|
|
ReadyCheck: &semaphore0.ReadyStage{
|
|
MaxWait: 90 * time.Second,
|
|
},
|
|
},
|
|
},
|
|
|
|
Distribution: model.Stages{
|
|
distribution.DistributeSshKey("*"),
|
|
rsync.RsyncStaged(),
|
|
},
|
|
|
|
Disposal: model.Stages{
|
|
terraform.Dispose(),
|
|
aws_ssh_key2.Dispose(),
|
|
},
|
|
|
|
Operation: model.Stages{
|
|
edge.SyncModelEdgeState(models.EdgeRouterTag),
|
|
fablib_5_operation.InfluxMetricsReporter(),
|
|
ztlib_5_operation.ModelMetricsWithIdMapper(nil, func(id string) string {
|
|
if id == "ctrl" {
|
|
return "#ctrl"
|
|
}
|
|
id = strings.ReplaceAll(id, ".", ":")
|
|
return "component.edgeId:" + id
|
|
}),
|
|
|
|
ztlib_5_operation.CircuitMetrics(5*time.Second, nil, func(id string) string {
|
|
id = strings.ReplaceAll(id, ".", ":")
|
|
return "component.edgeId:" + id
|
|
}),
|
|
model.StageActionF(func(run model.Run) error {
|
|
time.Sleep(time.Hour * 24)
|
|
return nil
|
|
}),
|
|
},
|
|
}
|
|
|
|
func InitBootstrapExtensions() {
|
|
model.AddBootstrapExtension(binding.AwsCredentialsLoader)
|
|
model.AddBootstrapExtension(aws_ssh_key.KeyManager)
|
|
}
|
|
|
|
func main() {
|
|
InitBootstrapExtensions()
|
|
fablab.InitModel(Model)
|
|
fablab.Run()
|
|
}
|