dhcp

package
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:     "dhcp-sync",
	Short:   "dhcp-sync command",
	Long:    `dhcp-sync tool is a tool populating the dhcpd.conf file from the PowerVS network and restart the dhcpd service.`,
	GroupID: "dhcp",
	PreRunE: func(cmd *cobra.Command, args []string) error {
		if pkg.Options.InstanceID == "" {
			return fmt.Errorf("--instance-id is required")
		}
		if pkg.Options.APIKey == "" {
			return fmt.Errorf("api-key can't be empty, pass the token via --api-key or set IBMCLOUD_API_KEY environment variable")
		}
		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		go doEvery(2*time.Minute, syncDHCPD)

		watcher, err := fsnotify.NewWatcher()
		if err != nil {
			klog.Fatal(err)
		}
		defer watcher.Close()

		done := make(chan bool)
		go func() {
			for {
				select {
				case event, ok := <-watcher.Events:
					if !ok {
						return
					}
					klog.Info("event:", event)
					if event.Op&fsnotify.Write == fsnotify.Write {
						klog.Info("modified file:", event.Name)
						klog.Info("restarting the dhcpd service")
						exitcode, out, err := utils.RunCMD("systemctl", "restart", "dhcpd")
						if exitcode != 0 {
							klog.Errorf("failed to restart the dhcpd service, exitcode: %d, stdout: %s, err: %s", exitcode, out, err)
						}
					}
				case err, ok := <-watcher.Errors:
					if !ok {
						return
					}
					klog.Error("error:", err)
				}
			}
		}()

		err = watcher.Add(file)
		if err != nil {
			klog.Fatal(err)
		}
		<-done
		return nil
	},
}

Functions

This section is empty.

Types

type InterfaceMTUOption added in v0.1.4

type InterfaceMTUOption string

func (InterfaceMTUOption) IndentedString added in v0.1.4

func (io InterfaceMTUOption) IndentedString(prefix string) string

IndentedString implements the method of the same name in the Statement interface

type RoutersOption

type RoutersOption []net.IP

func (RoutersOption) IndentedString

func (ro RoutersOption) IndentedString(prefix string) string

IndentedString implements the method of the same name in the Statement interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL