Пример #1
0
func (c *ENIClient) DescribeENIs() ([]*model.ENI, error) {
	resp, err := c.svc.DescribeNetworkInterfaces(nil)
	if err != nil {
		return nil, err
	}

	if len(resp.NetworkInterfaces) < 1 {
		return nil, nil
	}

	enis := make([]*model.ENI, 0)
	for _, iface := range resp.NetworkInterfaces {
		enis = append(enis, model.NewENI(iface))
	}

	instanceIDs := make([]string, 0)
	for _, eni := range enis {
		if id := eni.AttachedInstanceID(); id != "" {
			instanceIDs = append(instanceIDs, id)
		}
	}

	instances, err := c.DescribeInstancesByIDs(instanceIDs)
	if err != nil {
		return nil, err
	}
	if len(instances) < 1 {
		return enis, nil
	}
	//TODO make hashmap

	for _, eni := range enis {
		for _, instance := range instances {
			if eni.AttachedInstanceID() == instance.InstanceID() {
				eni.SetInstance(instance)
			}
		}
	}

	return enis, nil
}
Пример #2
0
func (c *ENIClient) DescribeENIByID(InterfaceID string) (*model.ENI, error) {
	params := &ec2.DescribeNetworkInterfacesInput{
		NetworkInterfaceIds: []*string{
			aws.String(InterfaceID),
		},
	}
	resp, err := c.svc.DescribeNetworkInterfaces(params)
	if err != nil {
		return nil, err
	}

	if len(resp.NetworkInterfaces) < 1 {
		return nil, nil
	}

	eni := model.NewENI(resp.NetworkInterfaces[0])
	instance, err := c.DescribeInstanceByID(eni.AttachedInstanceID())
	if err != nil {
		return nil, err
	}
	eni.SetInstance(instance)

	return eni, nil
}