jpictl: create machine directories on jpictl write
#33
@@ -104,3 +104,12 @@ func (m *Cluster) WriteStringFile(value string, name string, args ...any) error
|
|||||||
_, err = buf.WriteTo(f)
|
_, err = buf.WriteTo(f)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MkdirAll creates directories relative to the cluster's config directory
|
||||||
|
func (m *Cluster) MkdirAll(name string, args ...any) error {
|
||||||
|
if len(args) > 0 {
|
||||||
|
name = fmt.Sprintf(name, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fs.MkdirAll(m.dir, name, 0755)
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,10 +11,9 @@ import (
|
|||||||
|
|
||||||
// OpenFile opens a file on the machine's config directory with the specified flags
|
// OpenFile opens a file on the machine's config directory with the specified flags
|
||||||
func (m *Machine) OpenFile(name string, flags int, args ...any) (fs.File, error) {
|
func (m *Machine) OpenFile(name string, flags int, args ...any) (fs.File, error) {
|
||||||
base := m.zone.zones.dir
|
|
||||||
fullName := m.getFilename(name, args...)
|
fullName := m.getFilename(name, args...)
|
||||||
|
|
||||||
return fs.OpenFile(base, fullName, flags, 0644)
|
return m.zone.zones.OpenFile(fullName, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTruncFile creates or truncates a file on the machine's config directory
|
// CreateTruncFile creates or truncates a file on the machine's config directory
|
||||||
@@ -49,10 +48,9 @@ func (m *Machine) RemoveFile(name string, args ...any) error {
|
|||||||
|
|
||||||
// ReadFile reads a file from the machine's config directory
|
// ReadFile reads a file from the machine's config directory
|
||||||
func (m *Machine) ReadFile(name string, args ...any) ([]byte, error) {
|
func (m *Machine) ReadFile(name string, args ...any) ([]byte, error) {
|
||||||
base := m.zone.zones.dir
|
|
||||||
fullName := m.getFilename(name, args...)
|
fullName := m.getFilename(name, args...)
|
||||||
|
|
||||||
return fs.ReadFile(base, fullName)
|
return m.zone.zones.ReadFile(fullName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteStringFile writes the given content to a file on the machine's config directory
|
// WriteStringFile writes the given content to a file on the machine's config directory
|
||||||
@@ -62,6 +60,13 @@ func (m *Machine) WriteStringFile(value string, name string, args ...any) error
|
|||||||
return m.zone.zones.WriteStringFile(value, fullName)
|
return m.zone.zones.WriteStringFile(value, fullName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MkdirAll creates directories relative to the machine's config directory
|
||||||
|
func (m *Machine) MkdirAll(name string, args ...any) error {
|
||||||
|
fullName := m.getFilename(name, args...)
|
||||||
|
|
||||||
|
return m.zone.zones.MkdirAll(fullName)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Machine) getFilename(name string, args ...any) string {
|
func (m *Machine) getFilename(name string, args ...any) string {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
name = fmt.Sprintf(name, args...)
|
name = fmt.Sprintf(name, args...)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cluster
|
|||||||
// SyncAll updates all config files
|
// SyncAll updates all config files
|
||||||
func (m *Cluster) SyncAll() error {
|
func (m *Cluster) SyncAll() error {
|
||||||
for _, fn := range []func() error{
|
for _, fn := range []func() error{
|
||||||
|
m.SyncMkdirAll,
|
||||||
m.SyncAllWireguard,
|
m.SyncAllWireguard,
|
||||||
m.SyncAllCeph,
|
m.SyncAllCeph,
|
||||||
m.WriteHosts,
|
m.WriteHosts,
|
||||||
@@ -15,6 +16,20 @@ func (m *Cluster) SyncAll() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SyncMkdirAll creates the directories needed to store files
|
||||||
|
// required to represent the cluster.
|
||||||
|
func (m *Cluster) SyncMkdirAll() error {
|
||||||
|
err := m.MkdirAll(".")
|
||||||
|
if err == nil {
|
||||||
|
m.ForEachMachine(func(p *Machine) bool {
|
||||||
|
err = p.MkdirAll(".")
|
||||||
|
return err != nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// SyncAllWireguard updates all wireguard config files
|
// SyncAllWireguard updates all wireguard config files
|
||||||
func (m *Cluster) SyncAllWireguard() error {
|
func (m *Cluster) SyncAllWireguard() error {
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
Reference in New Issue
Block a user