disconnect

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: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

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

	Cobra: &cobra.Command{
		Use:          _CmdName,
		Short:        "disconnect a VPC Interface from a VPC Switch Port",
		Aliases:      []string{"disco"},
		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("Disconnecting VPC Interface from VPC Switch Port...")))

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

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

			portCfg := vpcp.Config{
				ID:        portID,
				Writeable: true,
			}

			vpcPort, err := vpcp.Open(portCfg)
			if err != nil {
				log.Error().Err(err).Str("port-id", portID.String()).Msg("VPC Switch Port open failed")
				return errors.Wrap(err, "unable to open VPC Switch Port")
			}
			defer vpcPort.Close()

			if err = vpcPort.Disconnect(interfaceID); err != nil {
				log.Error().Err(err).Object("port-id", portID).Object("interface-id", interfaceID).Msg("vpc switch port disconnect failed")
				return errors.Wrap(err, "unable to disconnect a VPC Interface from VPC Switch Port")
			}

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

			log.Info().Object("port-id", portID).Object("interface-id", interfaceID).Msg("VPC Interface disconnected from VPC Switch Port")

			return nil
		},
	},

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

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

		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