当前位置: 首页>>代码示例>>Golang>>正文


Golang ec2.NewFilter函数代码示例

本文整理汇总了Golang中launchpad/net/goamz/ec2.NewFilter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFilter函数的具体用法?Golang NewFilter怎么用?Golang NewFilter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewFilter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: discoverPeers

func (p *EC2CachePool) discoverPeers() ([]string, error) {
	f := ec2.NewFilter()
	f.Add("tag:server-type", "image-proxy")

	resp, err := p.Instances(nil, f)
	if err != nil {
		return nil, err
	}

	var ips []string
	for _, reserv := range resp.Reservations {
		for _, instance := range reserv.Instances {
			if instance.State.Name == "running" {
				ips = append(ips, instance.PrivateIPAddress)
			}
		}
	}

	peerIPs := make([]string, len(ips))
	_ = copy(peerIPs, ips)

	for i := range peerIPs {
		peerIPs[i] = fmt.Sprintf("http://%s:%s", peerIPs[i], *cacheport)
	}

	log.Println("Setting peers:", peerIPs)
	p.Set(peerIPs...)

	return ips, nil
}
开发者ID:projectweekend,项目名称:vip,代码行数:30,代码来源:peer.go

示例2: getInstances

func getInstances() []*Instance {
	auth := aws.Auth{aws_access_key, aws_secret_key}
	c = ec2.New(auth, aws.Regions[ec2_region])

	filter := ec2.NewFilter()
	filter.Add("instance-state-name", "running")
	resp, err := c.Instances(nil, filter)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	instances := []*Instance{}
	for _, reservation := range resp.Reservations {
		for _, instance := range reservation.Instances {
			name := ""
			for _, tag := range instance.Tags {
				if tag.Key == "Name" {
					name = tag.Value
					break
				}
			}
			if name != "" {
				i := &Instance{instance.DNSName, name}
				instances = append(instances, i)
			}
		}
	}

	return instances
}
开发者ID:postprefix,项目名称:ec2-ssh-config,代码行数:31,代码来源:ec2-ssh-config.go

示例3: TestDescribeInstancesExample1

func (s *S) TestDescribeInstancesExample1(c *C) {
	testServer.Response(200, nil, DescribeInstancesExample1)

	filter := ec2.NewFilter()
	filter.Add("key1", "value1")
	filter.Add("key2", "value2", "value3")

	resp, err := s.ec2.Instances([]string{"i-1", "i-2"}, nil)

	req := testServer.WaitRequest()
	c.Assert(req.Form["Action"], DeepEquals, []string{"DescribeInstances"})
	c.Assert(req.Form["InstanceId.1"], DeepEquals, []string{"i-1"})
	c.Assert(req.Form["InstanceId.2"], DeepEquals, []string{"i-2"})

	c.Assert(err, IsNil)
	c.Assert(resp.RequestId, Equals, "98e3c9a4-848c-4d6d-8e8a-b1bdEXAMPLE")
	c.Assert(resp.Reservations, HasLen, 2)

	expectedGroups := []ec2.SecurityGroup{{Name: "default", Id: "sg-67ad940e"}}
	r0 := resp.Reservations[0]
	c.Assert(r0.ReservationId, Equals, "r-b27e30d9")
	c.Assert(r0.OwnerId, Equals, "999988887777")
	c.Assert(r0.RequesterId, Equals, "854251627541")
	c.Assert(r0.SecurityGroups, DeepEquals, expectedGroups)
	c.Assert(r0.Instances, HasLen, 1)

	r0i := r0.Instances[0]
	c.Assert(r0i.InstanceId, Equals, "i-c5cd56af")
	c.Assert(r0i.PrivateDNSName, Equals, "domU-12-31-39-10-56-34.compute-1.internal")
	c.Assert(r0i.DNSName, Equals, "ec2-174-129-165-232.compute-1.amazonaws.com")
	c.Assert(r0i.PrivateIPAddress, Equals, "10.198.85.190")
	c.Assert(r0i.IPAddress, Equals, "174.129.165.232")
	c.Assert(r0i.AvailZone, Equals, "us-east-1b")
	c.Assert(r0i.SecurityGroups, DeepEquals, expectedGroups)
}
开发者ID:realestate-com-au,项目名称:goamz-launchpad,代码行数:35,代码来源:ec2_test.go

示例4: TestDescribeSecurityGroupsExampleWithFilter

func (s *S) TestDescribeSecurityGroupsExampleWithFilter(c *C) {
	testServer.Response(200, nil, DescribeSecurityGroupsExample)

	filter := ec2.NewFilter()
	filter.Add("ip-permission.protocol", "tcp")
	filter.Add("ip-permission.from-port", "22")
	filter.Add("ip-permission.to-port", "22")
	filter.Add("ip-permission.group-name", "app_server_group", "database_group")

	_, err := s.ec2.SecurityGroups(nil, filter)

	req := testServer.WaitRequest()
	c.Assert(req.Form["Action"], DeepEquals, []string{"DescribeSecurityGroups"})
	c.Assert(req.Form["Filter.1.Name"], DeepEquals, []string{"ip-permission.from-port"})
	c.Assert(req.Form["Filter.1.Value.1"], DeepEquals, []string{"22"})
	c.Assert(req.Form["Filter.2.Name"], DeepEquals, []string{"ip-permission.group-name"})
	c.Assert(req.Form["Filter.2.Value.1"], DeepEquals, []string{"app_server_group"})
	c.Assert(req.Form["Filter.2.Value.2"], DeepEquals, []string{"database_group"})
	c.Assert(req.Form["Filter.3.Name"], DeepEquals, []string{"ip-permission.protocol"})
	c.Assert(req.Form["Filter.3.Value.1"], DeepEquals, []string{"tcp"})
	c.Assert(req.Form["Filter.4.Name"], DeepEquals, []string{"ip-permission.to-port"})
	c.Assert(req.Form["Filter.4.Value.1"], DeepEquals, []string{"22"})

	c.Assert(err, IsNil)
}
开发者ID:realestate-com-au,项目名称:goamz-launchpad,代码行数:25,代码来源:ec2_test.go

示例5: defaultAMI

func defaultAMI(conn *ec2.EC2) (string, error) {
	filter := ec2.NewFilter()
	imageName := "amzn-ami-hvm-2014.03.2.x86_64-ebs"
	filter.Add("name", imageName)
	resp, _ := conn.Images(nil, filter)

	if len(resp.Images) == 0 {
		return "", fmt.Errorf("Unable to retrieve ami id for image name: %s", imageName)
	}

	return resp.Images[0].Id, nil
}
开发者ID:rgbkrk,项目名称:libswarm,代码行数:12,代码来源:ec2.go

示例6: searchByFilter

func searchByFilter(e *ec2.EC2, key, value string) (*ec2.Instance, error) {
	filter := ec2.NewFilter()
	filter.Add(key, value)
	resp, err := e.Instances(nil, filter)
	if err != nil {
		return nil, errors.New("EC2 API call failed. " +
			"Check your AWS credentials and system clock")
	}
	if len(resp.Reservations) != 1 {
		return nil, errors.New("no instance with " + key + "=" + value)
	}
	return &resp.Reservations[0].Instances[0], nil
}
开发者ID:RubanDeventhiran,项目名称:ansible-kick,代码行数:13,代码来源:ec2.go

示例7: TestDescribeImagesExample

func (s *S) TestDescribeImagesExample(c *C) {
	testServer.Response(200, nil, DescribeImagesExample)

	filter := ec2.NewFilter()
	filter.Add("key1", "value1")
	filter.Add("key2", "value2", "value3")

	resp, err := s.ec2.Images([]string{"ami-1", "ami-2"}, filter)

	req := testServer.WaitRequest()
	c.Assert(req.Form["Action"], DeepEquals, []string{"DescribeImages"})
	c.Assert(req.Form["ImageId.1"], DeepEquals, []string{"ami-1"})
	c.Assert(req.Form["ImageId.2"], DeepEquals, []string{"ami-2"})
	c.Assert(req.Form["Filter.1.Name"], DeepEquals, []string{"key1"})
	c.Assert(req.Form["Filter.1.Value.1"], DeepEquals, []string{"value1"})
	c.Assert(req.Form["Filter.1.Value.2"], IsNil)
	c.Assert(req.Form["Filter.2.Name"], DeepEquals, []string{"key2"})
	c.Assert(req.Form["Filter.2.Value.1"], DeepEquals, []string{"value2"})
	c.Assert(req.Form["Filter.2.Value.2"], DeepEquals, []string{"value3"})

	c.Assert(err, IsNil)
	c.Assert(resp.RequestId, Equals, "4a4a27a2-2e7c-475d-b35b-ca822EXAMPLE")
	c.Assert(resp.Images, HasLen, 1)

	i0 := resp.Images[0]
	c.Assert(i0.Id, Equals, "ami-a2469acf")
	c.Assert(i0.Type, Equals, "machine")
	c.Assert(i0.Name, Equals, "example-marketplace-amzn-ami.1")
	c.Assert(i0.Description, Equals, "Amazon Linux AMI i386 EBS")
	c.Assert(i0.Location, Equals, "aws-marketplace/example-marketplace-amzn-ami.1")
	c.Assert(i0.State, Equals, "available")
	c.Assert(i0.Public, Equals, true)
	c.Assert(i0.OwnerId, Equals, "123456789999")
	c.Assert(i0.OwnerAlias, Equals, "aws-marketplace")
	c.Assert(i0.Architecture, Equals, "i386")
	c.Assert(i0.KernelId, Equals, "aki-805ea7e9")
	c.Assert(i0.RootDeviceType, Equals, "ebs")
	c.Assert(i0.RootDeviceName, Equals, "/dev/sda1")
	c.Assert(i0.VirtualizationType, Equals, "paravirtual")
	c.Assert(i0.Hypervisor, Equals, "xen")

	c.Assert(i0.BlockDevices, HasLen, 1)
	c.Assert(i0.BlockDevices[0].DeviceName, Equals, "/dev/sda1")
	c.Assert(i0.BlockDevices[0].SnapshotId, Equals, "snap-787e9403")
	c.Assert(i0.BlockDevices[0].VolumeSize, Equals, int64(8))
	c.Assert(i0.BlockDevices[0].DeleteOnTermination, Equals, true)
}
开发者ID:realestate-com-au,项目名称:goamz-launchpad,代码行数:47,代码来源:ec2_test.go

示例8: AllInstances

func (e *environ) AllInstances() ([]environs.Instance, error) {
	filter := ec2.NewFilter()
	filter.Add("instance-state-name", "pending", "running")
	filter.Add("group-name", e.jujuGroupName())
	resp, err := e.ec2().Instances(nil, filter)
	if err != nil {
		return nil, err
	}
	var insts []environs.Instance
	for _, r := range resp.Reservations {
		for i := range r.Instances {
			inst := r.Instances[i]
			insts = append(insts, &instance{e, &inst})
		}
	}
	return insts, nil
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:17,代码来源:ec2.go

示例9: AllInstances

func (e *environ) AllInstances() ([]instance.Instance, error) {
	filter := ec2.NewFilter()
	filter.Add("instance-state-name", "pending", "running")
	filter.Add("group-name", e.jujuGroupName())
	resp, err := e.ec2().Instances(nil, filter)
	if err != nil {
		return nil, err
	}
	var insts []instance.Instance
	for _, r := range resp.Reservations {
		for i := range r.Instances {
			inst := r.Instances[i]
			// TODO(wallyworld): lookup the details to fill in the instance type data
			insts = append(insts, &ec2Instance{e: e, Instance: &inst})
		}
	}
	return insts, nil
}
开发者ID:CSRedRat,项目名称:juju-core,代码行数:18,代码来源:ec2.go

示例10: TestAvailabilityZones

func (s *LocalServerSuite) TestAvailabilityZones(c *C) {
	s.srv.srv.SetAvailabilityZones([]ec2.AvailabilityZoneInfo{{
		AvailabilityZone: ec2.AvailabilityZone{
			Name:   "us-east-1a",
			Region: "us-east-1",
		},
		State: "available",
	}, {
		AvailabilityZone: ec2.AvailabilityZone{
			Name:   "us-east-1b",
			Region: "us-east-1",
		},
		State: "impaired",
	}, {
		AvailabilityZone: ec2.AvailabilityZone{
			Name:   "us-west-1a",
			Region: "us-west-1",
		},
		State: "available",
	}, {
		AvailabilityZone: ec2.AvailabilityZone{
			Name:   "us-west-1b",
			Region: "us-west-1",
		},
		State:      "unavailable",
		MessageSet: []string{"down for maintenance"},
	}})

	resp, err := s.ec2.AvailabilityZones(nil)
	c.Assert(err, IsNil)
	c.Assert(resp.Zones, HasLen, 4)
	c.Assert(resp.Zones[0].Name, Equals, "us-east-1a")
	c.Assert(resp.Zones[1].Name, Equals, "us-east-1b")
	c.Assert(resp.Zones[2].Name, Equals, "us-west-1a")
	c.Assert(resp.Zones[3].Name, Equals, "us-west-1b")

	filter := ec2.NewFilter()
	filter.Add("region-name", "us-east-1")
	resp, err = s.ec2.AvailabilityZones(filter)
	c.Assert(err, IsNil)
	c.Assert(resp.Zones, HasLen, 2)
	c.Assert(resp.Zones[0].Name, Equals, "us-east-1a")
	c.Assert(resp.Zones[1].Name, Equals, "us-east-1b")
}
开发者ID:BillTheBest,项目名称:libswarm,代码行数:44,代码来源:ec2t_test.go

示例11: getLocalIP

func getLocalIP(ec2conn *ec2.EC2) string {
	f := ec2.NewFilter()
	f.Add("tag:server-type", "image-proxy")

	resp, err := ec2conn.Instances(nil, f)
	if err != nil {
		return ""
	}

	for _, reserv := range resp.Reservations {
		for _, instance := range reserv.Instances {
			if localAddress(instance.PrivateIPAddress) {
				return instance.PrivateIPAddress
			}
		}
	}

	return ""
}
开发者ID:projectweekend,项目名称:vip,代码行数:19,代码来源:peer.go

示例12: gatherInstances

// gatherInstances tries to get information on each instance
// id whose corresponding insts slot is nil.
// It returns environs.ErrPartialInstances if the insts
// slice has not been completely filled.
func (e *environ) gatherInstances(ids []instance.Id, insts []instance.Instance) error {
	var need []string
	for i, inst := range insts {
		if inst == nil {
			need = append(need, string(ids[i]))
		}
	}
	if len(need) == 0 {
		return nil
	}
	filter := ec2.NewFilter()
	filter.Add("instance-state-name", "pending", "running")
	filter.Add("group-name", e.jujuGroupName())
	filter.Add("instance-id", need...)
	resp, err := e.ec2().Instances(nil, filter)
	if err != nil {
		return err
	}
	n := 0
	// For each requested id, add it to the returned instances
	// if we find it in the response.
	for i, id := range ids {
		if insts[i] != nil {
			continue
		}
		for j := range resp.Reservations {
			r := &resp.Reservations[j]
			for k := range r.Instances {
				if r.Instances[k].InstanceId == string(id) {
					inst := r.Instances[k]
					// TODO(wallyworld): lookup the details to fill in the instance type data
					insts[i] = &ec2Instance{e: e, Instance: &inst}
					n++
				}
			}
		}
	}
	if n < len(ids) {
		return environs.ErrPartialInstances
	}
	return nil
}
开发者ID:CSRedRat,项目名称:juju-core,代码行数:46,代码来源:ec2.go

示例13: waitForDnsName

func waitForDnsName(ec2Inst *ec2.EC2, instance *ec2.Instance) (*ec2.Instance, error) {
	t0 := time.Now()
	for instance.DNSName == "" {
		instId := instance.InstanceId
		if time.Now().Sub(t0) > maxWaitTime {
			return nil, fmt.Errorf("ec2: time out waiting for instance %s to start", instId)
		}
		log.Debugf("ec2: waiting for dnsname for instance %s", instId)
		time.Sleep(500 * time.Millisecond)
		resp, err := ec2Inst.Instances([]string{instance.InstanceId}, ec2.NewFilter())
		if err != nil {
			return nil, err
		}
		if len(resp.Reservations) == 0 || len(resp.Reservations[0].Instances) == 0 {
			return nil, fmt.Errorf("No instances returned")
		}
		instance = &resp.Reservations[0].Instances[0]
	}
	return instance, nil
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:20,代码来源:iaas.go

示例14: findInstance

func (c *ec2Client) findInstance() (instance *ec2.Instance, err error) {
	filter := ec2.NewFilter()
	filter.Add("tag:Name", c.config.tag)
	resp, err := c.ec2Conn.Instances([]string{}, filter)

	if err != nil {
		return nil, err
	} else {
		if resp.Reservations == nil {
			return nil, nil
		}

		instance := resp.Reservations[0].Instances[0]

		if instance.State.Name == "running" || instance.State.Name == "pending" {
			return &instance, nil
		}

		return nil, nil
	}
}
开发者ID:rgbkrk,项目名称:libswarm,代码行数:21,代码来源:ec2.go

示例15: startInstance

func (c *ec2Client) startInstance() error {
	// TODO: allow more than one sg in the future
	options := ec2.RunInstances{
		SubnetId:       c.config.subnetId,
		ImageId:        c.config.ami,
		InstanceType:   c.config.instanceType,
		KeyName:        c.config.keypair,
		AvailZone:      c.config.zone,
		SecurityGroups: []ec2.SecurityGroup{ec2.SecurityGroup{Id: c.config.securityGroupId}},
		UserData:       []byte(userdata),
	}

	resp, err := c.ec2Conn.RunInstances(&options)
	if err != nil {
		return err
	}

	// TODO (aaron): this really could be multiple instances, not just 1
	i := resp.Instances[0]

	for i.State.Name != "running" {
		time.Sleep(3 * time.Second)
		fmt.Printf("Waiting for instance to come up.  Current State: %s\n",
			i.State.Name)

		resp, err := c.ec2Conn.Instances([]string{i.InstanceId}, ec2.NewFilter())

		if err != nil {
			return err
		}

		i = resp.Reservations[0].Instances[0]
	}

	c.instance = &i

	fmt.Printf("Instance up and running - id: %s\n", i.InstanceId)
	return nil
}
开发者ID:rgbkrk,项目名称:libswarm,代码行数:39,代码来源:ec2.go


注:本文中的launchpad/net/goamz/ec2.NewFilter函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。