Compare commits
3 Commits
v0.4.16
...
eb9a44b142
| Author | SHA1 | Date | |
|---|---|---|---|
| eb9a44b142 | |||
| 6f5ca3f235 | |||
| 296d4007ff |
@@ -0,0 +1,102 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.jpi.io/amery/jpictl/pkg/zones"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Command
|
||||||
|
var gatewayCmd = &cobra.Command{
|
||||||
|
Use: "gateway",
|
||||||
|
Short: "gateway operates on ring0/ring1 gateways",
|
||||||
|
}
|
||||||
|
|
||||||
|
// gateway set
|
||||||
|
var gatewaySetCmd = &cobra.Command{
|
||||||
|
Use: "set",
|
||||||
|
Short: "gateway set sets machines as gateways",
|
||||||
|
RunE: func(_ *cobra.Command, args []string) error {
|
||||||
|
m, err := cfg.LoadZones(false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, arg := range args {
|
||||||
|
err = gatewaySet(m, arg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func gatewaySet(_ zones.ZoneIterator, _ string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// gateway unset
|
||||||
|
var gatewayUnsetCmd = &cobra.Command{
|
||||||
|
Use: "unset",
|
||||||
|
Short: "gateway unset sets machines as non-gateways",
|
||||||
|
RunE: func(_ *cobra.Command, args []string) error {
|
||||||
|
m, err := cfg.LoadZones(false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, arg := range args {
|
||||||
|
err = gatewayUnset(m, arg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func gatewayUnset(_ zones.ZoneIterator, _ string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// gateway list
|
||||||
|
var gatewayListCmd = &cobra.Command{
|
||||||
|
Use: "list",
|
||||||
|
Short: "gateway list lists gateways",
|
||||||
|
RunE: func(_ *cobra.Command, args []string) error {
|
||||||
|
m, err := cfg.LoadZones(false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case len(args) == 0:
|
||||||
|
return gatewayListAll(m)
|
||||||
|
default:
|
||||||
|
for _, arg := range args {
|
||||||
|
err = gatewayList(m, arg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func gatewayListAll(_ zones.ZoneIterator) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func gatewayList(_ zones.ZoneIterator, _ string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(gatewayCmd)
|
||||||
|
|
||||||
|
gatewayCmd.AddCommand(gatewaySetCmd)
|
||||||
|
gatewayCmd.AddCommand(gatewayUnsetCmd)
|
||||||
|
gatewayCmd.AddCommand(gatewayListCmd)
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package zones
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
fs "github.com/hack-pad/hackpadfs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// OpenFile opens a file on the cluster's config directory with the specified flags
|
||||||
|
func (m *Zones) OpenFile(name string, flags int, args ...any) (fs.File, error) {
|
||||||
|
if len(args) > 0 {
|
||||||
|
name = fmt.Sprintf(name, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fs.OpenFile(m.dir, name, flags, 0644)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTruncFile creates or truncates a file on the cluster's config directory
|
||||||
|
func (m *Zones) CreateTruncFile(name string, args ...any) (io.WriteCloser, error) {
|
||||||
|
return m.openWriter(name, os.O_CREATE|os.O_TRUNC, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFile creates a file on the cluster's config directory
|
||||||
|
func (m *Zones) CreateFile(name string, args ...any) (io.WriteCloser, error) {
|
||||||
|
return m.openWriter(name, os.O_CREATE, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Zones) openWriter(name string, flags int, args ...any) (io.WriteCloser, error) {
|
||||||
|
f, err := m.OpenFile(name, os.O_WRONLY|flags, args...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return f.(io.WriteCloser), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadFile reads a file from the cluster's config directory
|
||||||
|
func (m *Zones) ReadFile(name string, args ...any) ([]byte, error) {
|
||||||
|
if len(args) > 0 {
|
||||||
|
name = fmt.Sprintf(name, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fs.ReadFile(m.dir, name)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user