cli, engine, etcd, lib: Move the hostname value to the API

Every world implementation needs a unique UUID, might as well move this
to the API.
This commit is contained in:
James Shubin
2025-03-19 05:41:04 -04:00
parent 02fca6409a
commit 5665259784
5 changed files with 12 additions and 14 deletions

View File

@@ -199,7 +199,6 @@ func (obj *DeployArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error
var world engine.World var world engine.World
world = &etcd.World{ // XXX: What should some of these fields be? world = &etcd.World{ // XXX: What should some of these fields be?
//Hostname: hostname,
Client: etcdClient, Client: etcdClient,
//MetadataPrefix: lib.MetadataPrefix, //MetadataPrefix: lib.MetadataPrefix,
//StoragePrefix: lib.StoragePrefix, //StoragePrefix: lib.StoragePrefix,
@@ -210,7 +209,6 @@ func (obj *DeployArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error
if obj.SshUrl != "" { // alternate world implementation over SSH if obj.SshUrl != "" { // alternate world implementation over SSH
world = &etcdSSH.World{ world = &etcdSSH.World{
URL: obj.SshUrl, URL: obj.SshUrl,
//Hostname: hostname,
//Client: client, //Client: client,
NS: lib.NS, NS: lib.NS,
//MetadataPrefix: lib.MetadataPrefix, //MetadataPrefix: lib.MetadataPrefix,
@@ -224,6 +222,7 @@ func (obj *DeployArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error
return false, fmt.Errorf("--ssh-url is not implemented yet") return false, fmt.Errorf("--ssh-url is not implemented yet")
} }
worldInit := &engine.WorldInit{ worldInit := &engine.WorldInit{
Hostname: "", // XXX: Should we set this?
Debug: data.Flags.Debug, Debug: data.Flags.Debug,
Logf: func(format string, v ...interface{}) { Logf: func(format string, v ...interface{}) {
Logf("world: etcd: "+format, v...) Logf("world: etcd: "+format, v...)

View File

@@ -39,6 +39,9 @@ import (
// WorldInit is some data passed in when starting the World interface. // WorldInit is some data passed in when starting the World interface.
// TODO: This is a lousy struct name, feel free to change it. // TODO: This is a lousy struct name, feel free to change it.
type WorldInit struct { type WorldInit struct {
// Hostname is the UUID we use to represent ourselves to everyone else.
Hostname string
// Debug represents if we're running in debug mode or not. // Debug represents if we're running in debug mode or not.
Debug bool Debug bool

View File

@@ -81,7 +81,6 @@ type World struct {
// NS is the etcd namespace to use. // NS is the etcd namespace to use.
NS string NS string
Hostname string // uuid for the consumer of these
MetadataPrefix string // expected metadata prefix MetadataPrefix string // expected metadata prefix
StoragePrefix string // storage prefix for etcdfs storage StoragePrefix string // storage prefix for etcdfs storage
StandaloneFs engine.Fs // store an fs here for local usage StandaloneFs engine.Fs // store an fs here for local usage
@@ -305,7 +304,6 @@ func (obj *World) Init(init *engine.WorldInit) error {
obj.World = &etcd.World{ obj.World = &etcd.World{
// TODO: Pass through more data if the struct for etcd changes. // TODO: Pass through more data if the struct for etcd changes.
Hostname: obj.Hostname,
Client: c, Client: c,
MetadataPrefix: obj.MetadataPrefix, MetadataPrefix: obj.MetadataPrefix,
StoragePrefix: obj.StoragePrefix, StoragePrefix: obj.StoragePrefix,

View File

@@ -53,7 +53,6 @@ import (
// World is an etcd backed implementation of the World interface. // World is an etcd backed implementation of the World interface.
type World struct { type World struct {
// NOTE: Update the etcd/ssh/ World struct if this one changes. // NOTE: Update the etcd/ssh/ World struct if this one changes.
Hostname string // uuid for the consumer of these
// XXX: build your own etcd client... // XXX: build your own etcd client...
Client interfaces.Client Client interfaces.Client
MetadataPrefix string // expected metadata prefix MetadataPrefix string // expected metadata prefix
@@ -128,7 +127,7 @@ func (obj *World) ResWatch(ctx context.Context) (chan error, error) {
// ResExport exports a list of resources under our hostname namespace. // ResExport exports a list of resources under our hostname namespace.
// Subsequent calls replace the previously set collection atomically. // Subsequent calls replace the previously set collection atomically.
func (obj *World) ResExport(ctx context.Context, resourceList []engine.Res) error { func (obj *World) ResExport(ctx context.Context, resourceList []engine.Res) error {
return resources.SetResources(ctx, obj.Client, obj.Hostname, resourceList) return resources.SetResources(ctx, obj.Client, obj.init.Hostname, resourceList)
} }
// ResCollect gets the collection of exported resources which match the filter. // ResCollect gets the collection of exported resources which match the filter.
@@ -226,12 +225,12 @@ func (obj *World) StrMapGet(ctx context.Context, namespace string) (map[string]s
// StrMapSet sets the namespace value to a particular string under the identity // StrMapSet sets the namespace value to a particular string under the identity
// of its own hostname. // of its own hostname.
func (obj *World) StrMapSet(ctx context.Context, namespace, value string) error { func (obj *World) StrMapSet(ctx context.Context, namespace, value string) error {
return strmap.SetStrMap(ctx, obj.Client, obj.Hostname, namespace, &value) return strmap.SetStrMap(ctx, obj.Client, obj.init.Hostname, namespace, &value)
} }
// StrMapDel deletes the value in a particular namespace. // StrMapDel deletes the value in a particular namespace.
func (obj *World) StrMapDel(ctx context.Context, namespace string) error { func (obj *World) StrMapDel(ctx context.Context, namespace string) error {
return strmap.SetStrMap(ctx, obj.Client, obj.Hostname, namespace, nil) return strmap.SetStrMap(ctx, obj.Client, obj.init.Hostname, namespace, nil)
} }
// Scheduler returns a scheduling result of hosts in a particular namespace. // Scheduler returns a scheduling result of hosts in a particular namespace.
@@ -246,7 +245,7 @@ func (obj *World) Scheduler(namespace string, opts ...scheduler.Option) (*schedu
modifiedOpts = append(modifiedOpts, scheduler.Logf(obj.init.Logf)) modifiedOpts = append(modifiedOpts, scheduler.Logf(obj.init.Logf))
path := fmt.Sprintf(schedulerPathFmt, namespace) path := fmt.Sprintf(schedulerPathFmt, namespace)
return scheduler.Schedule(obj.Client.GetClient(), path, obj.Hostname, modifiedOpts...) return scheduler.Schedule(obj.Client.GetClient(), path, obj.init.Hostname, modifiedOpts...)
} }
// URI returns the current FS URI. // URI returns the current FS URI.

View File

@@ -621,7 +621,6 @@ func (obj *Main) Run() error {
// an etcd component from the etcd package added in. // an etcd component from the etcd package added in.
var world engine.World var world engine.World
world = &etcd.World{ world = &etcd.World{
Hostname: hostname,
Client: client, Client: client,
//NS: NS, //NS: NS,
MetadataPrefix: MetadataPrefix, MetadataPrefix: MetadataPrefix,
@@ -638,7 +637,6 @@ func (obj *Main) Run() error {
world = &etcdSSH.World{ world = &etcdSSH.World{
URL: obj.SshUrl, URL: obj.SshUrl,
Seeds: obj.Seeds, Seeds: obj.Seeds,
Hostname: hostname,
NS: NS, NS: NS,
MetadataPrefix: MetadataPrefix, MetadataPrefix: MetadataPrefix,
StoragePrefix: StoragePrefix, StoragePrefix: StoragePrefix,
@@ -652,6 +650,7 @@ func (obj *Main) Run() error {
} }
} }
worldInit := &engine.WorldInit{ worldInit := &engine.WorldInit{
Hostname: hostname,
Debug: obj.Debug, Debug: obj.Debug,
Logf: func(format string, v ...interface{}) { Logf: func(format string, v ...interface{}) {
obj.Logf("world: etcd: "+format, v...) obj.Logf("world: etcd: "+format, v...)