Example #1
0
func doDetach(c *cli.Context) error {
	if len(c.Args()) < 1 {
		cli.ShowCommandHelp(c, "detach")
		return errors.New("ENI_ID required")
	}

	eniID := c.Args().Get(0)

	eni, err := aws.NewENIClient().WithLogWriter(os.Stdout).DetachENIWithWaiter(&aws.DetachENIParam{
		InterfaceID: eniID,
	}, &aws.WaiterParam{
		MaxAttempts: c.Int("max-attempts"),
		IntervalSec: c.Int("interval"),
	})
	if err != nil {
		return err
	}
	if eni == nil {
		log.Infof("%s already detached", eniID)
		return nil
	}

	log.Infof("%s detached", eniID)

	return nil
}
Example #2
0
func doGrab(c *cli.Context) error {
	if len(c.Args()) < 1 {
		cli.ShowCommandHelp(c, "grab")
		return errors.New("ENI_ID required")
	}

	eniID := c.Args().Get(0)

	var instanceID string
	if instanceID = c.String("instanceid"); instanceID == "" {
		var err error
		instanceID, err = aws.NewMetaDataClient().GetInstanceID()
		if err != nil {
			return err
		}
	}

	awscli := aws.NewENIClient().WithLogWriter(os.Stdout)

	// Check instance id existence
	instance, err := awscli.DescribeInstanceByID(instanceID)
	if err != nil {
		return err
	}
	if instance == nil {
		return fmt.Errorf("No such instance %s", instanceID)
	}

	eni, err := awscli.GrabENI(&aws.GrabENIParam{
		InterfaceID: eniID,
		InstanceID:  instanceID,
		DeviceIndex: c.Int("deviceindex"),
	}, &aws.WaiterParam{
		MaxAttempts: c.Int("max-attempts"),
		IntervalSec: c.Int("interval"),
	})
	if err != nil {
		return err
	}
	if eni == nil {
		log.Infof("%s already attached to instance %s", eniID, instanceID)
		return nil
	}

	log.Infof("%s attached to instance %s", eniID, instanceID)

	return nil
}
Example #3
0
func cmdNotFound(c *cli.Context, command string) {
	log.Infof(
		"%s: '%s' is not a %s command. See '%s --help'.",
		c.App.Name,
		command,
		c.App.Name,
		os.Args[0],
	)
}