예제 #1
0
파일: detach.go 프로젝트: dekokun/grabeni
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
}
예제 #2
0
파일: grab.go 프로젝트: dekokun/grabeni
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
}
예제 #3
0
파일: grabeni.go 프로젝트: dekokun/grabeni
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],
	)
}