uplink

package
v0.0.0-...-b801540 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2018 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &command.Command{
	Name: _CmdName,

	Cobra: &cobra.Command{
		Use:          _CmdName,
		Short:        "Sets a given switch port as the uplink",
		SilenceUsage: true,
		Args:         cobra.NoArgs,
		PreRunE: func(cmd *cobra.Command, args []string) error {
			return nil
		},

		RunE: func(cmd *cobra.Command, args []string) (err error) {
			cons := conswriter.GetTerminal()

			cons.Write([]byte(fmt.Sprintf("Designating VPC Switch Port as Uplink Port...")))

			portID, err := flag.GetPortID(viper.GetViper(), _KeyPortID)
			if err != nil {
				return errors.Wrap(err, "unable to get switch port ID")
			}

			switchID, err := flag.GetSwitchID(viper.GetViper(), _KeySwitchID)
			if err != nil {
				return errors.Wrap(err, "unable to get switch ID")
			}

			switchCfg := vpcsw.Config{
				ID:        switchID,
				Writeable: true,
			}

			vpcSwitch, err := vpcsw.Open(switchCfg)
			if err != nil {
				log.Error().Err(err).Object("switch-id", switchID).Msg("VPC Switch open failed")
				return errors.Wrap(err, "unable to open VPC Switch")
			}
			defer vpcSwitch.Close()

			var portMAC net.HardwareAddr = portID.Node[:]
			if err := vpcSwitch.PortUplinkSet(portID, portMAC); err != nil {
				log.Error().Err(err).Object("port-id", portID).Object("switch-cfg", switchCfg).Msg("failed to set VPC Switch Port as an Uplink port")
				return errors.Wrap(err, "unable to create a VPC Switch Port uplink")
			}

			cons.Write([]byte("done.\n"))

			log.Info().Object("switch-id", switchID).Object("port-id", portID).Msg("Uplink port for VPC Switch set")

			return nil
		},
	},

	Setup: func(self *command.Command) error {
		if err := flag.AddPortID(self, _KeyPortID, true); err != nil {
			return errors.Wrap(err, "unable to register Port ID flag on VPC Switch Port uplink")
		}

		if err := flag.AddSwitchID(self, _KeySwitchID, true); err != nil {
			return errors.Wrap(err, "unable to register Switch ID flag on VPC Switch Port uplink")
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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