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 doList(c *cli.Context) error {
	enis, err := aws.NewENIClient().WithLogWriter(os.Stdout).DescribeENIs()
	if err != nil {
		return err
	}
	if enis == nil {
		return nil
	}

	format.PrintENIs(os.Stdout, enis)

	return nil
}
Example #3
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 #4
0
func doStatus(c *cli.Context) error {
	if len(c.Args()) < 1 {
		cli.ShowCommandHelp(c, "status")
		return errors.New("ENI_ID required")
	}

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

	eni, err := aws.NewENIClient().WithLogWriter(os.Stdout).DescribeENIByID(eniID)
	if err != nil {
		return err
	}
	if eni == nil {
		return nil
	}

	format.PrintENI(os.Stdout, eni)

	return nil
}