當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ec2.NewFilter函數代碼示例

本文整理匯總了Golang中github.com/mitchellh/goamz/ec2.NewFilter函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFilter函數的具體用法?Golang NewFilter怎麽用?Golang NewFilter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewFilter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: IPAddress

// IPAddress is an implementation of Instances.IPAddress.
func (aws *AWSCloud) IPAddress(name string) (net.IP, error) {
	f := ec2.NewFilter()
	f.Add("private-dns-name", name)

	resp, err := aws.ec2.Instances(nil, f)
	if err != nil {
		return nil, err
	}
	if len(resp.Reservations) == 0 {
		return nil, fmt.Errorf("no reservations found for host: %s", name)
	}
	if len(resp.Reservations) > 1 {
		return nil, fmt.Errorf("multiple reservations found for host: %s", name)
	}
	if len(resp.Reservations[0].Instances) == 0 {
		return nil, fmt.Errorf("no instances found for host: %s", name)
	}
	if len(resp.Reservations[0].Instances) > 1 {
		return nil, fmt.Errorf("multiple instances found for host: %s", name)
	}

	ipAddress := resp.Reservations[0].Instances[0].PrivateIpAddress
	ip := net.ParseIP(ipAddress)
	if ip == nil {
		return nil, fmt.Errorf("invalid network IP: %s", ipAddress)
	}
	return ip, nil
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:29,代碼來源:aws.go

示例2: getfilter

func getfilter(args []string) (*ec2.Filter, []string) {
	filter := ec2.NewFilter()
	for len(args) > 1 {
		if args[0][0] != '-' {
			break
		}
		switch args[0] {
		case "-image":
			filter.Add("image-id", args[1])
		case "-type":
			filter.Add("instance-type", "*"+args[1]+"*")
		case "-state":
			filter.Add("instance-state-name", "*"+args[1]+"*")
		case "-name":
			filter.Add("tag:Name", "*"+args[1]+"*")
		case "-stage":
			filter.Add("tag:stage", "*"+args[1]+"*")
		default:
			filter.Add(args[0][1:], "*"+args[1]+"*")
		}
		if len(args) > 2 {
			args = args[2:]
		} else {
			args = nil
			break
		}
		//filter.Add("tag:Name", "*"+args[1]+"*")
	}
	return filter, args
}
開發者ID:peergum,項目名稱:goaws,代碼行數:30,代碼來源:goaws.go

示例3: testAccCheckRouteTableDestroy

func testAccCheckRouteTableDestroy(s *terraform.State) error {
	conn := testAccProvider.Meta().(*AWSClient).ec2conn

	for _, rs := range s.RootModule().Resources {
		if rs.Type != "aws_route_table" {
			continue
		}

		// Try to find the resource
		resp, err := conn.DescribeRouteTables(
			[]string{rs.Primary.ID}, ec2.NewFilter())
		if err == nil {
			if len(resp.RouteTables) > 0 {
				return fmt.Errorf("still exist.")
			}

			return nil
		}

		// Verify the error is what we want
		ec2err, ok := err.(*ec2.Error)
		if !ok {
			return err
		}
		if ec2err.Code != "InvalidRouteTableID.NotFound" {
			return err
		}
	}

	return nil
}
開發者ID:packetloop,項目名稱:terraform,代碼行數:31,代碼來源:resource_aws_route_table_test.go

示例4: testAccCheckRouteTableAssociationExists

func testAccCheckRouteTableAssociationExists(n string, v *ec2.RouteTable) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		rs, ok := s.Resources[n]
		if !ok {
			return fmt.Errorf("Not found: %s", n)
		}

		if rs.ID == "" {
			return fmt.Errorf("No ID is set")
		}

		conn := testAccProvider.ec2conn
		resp, err := conn.DescribeRouteTables(
			[]string{rs.Attributes["route_table_id"]}, ec2.NewFilter())
		if err != nil {
			return err
		}
		if len(resp.RouteTables) == 0 {
			return fmt.Errorf("RouteTable not found")
		}

		*v = resp.RouteTables[0]

		if len(v.Associations) == 0 {
			return fmt.Errorf("no associations")
		}

		return nil
	}
}
開發者ID:GeorgeErickson,項目名稱:terraform-1,代碼行數:30,代碼來源:resource_aws_route_table_association_test.go

示例5: 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:ericcapricorn,項目名稱:kubernetes,代碼行數:25,代碼來源:ec2_test.go

示例6: InstanceStateRefreshFunc

// InstanceStateRefreshFunc returns a StateRefreshFunc that is used to watch
// an EC2 instance.
func InstanceStateRefreshFunc(conn *ec2.EC2, i *ec2.Instance) StateRefreshFunc {
	return func() (interface{}, string, error) {
		resp, err := conn.Instances([]string{i.InstanceId}, ec2.NewFilter())
		if err != nil {
			if ec2err, ok := err.(*ec2.Error); ok && ec2err.Code == "InvalidInstanceID.NotFound" {
				// Set this to nil as if we didn't find anything.
				resp = nil
			} else if isTransientNetworkError(err) {
				// Transient network error, treat it as if we didn't find anything
				resp = nil
			} else {
				log.Printf("Error on InstanceStateRefresh: %s", err)
				return nil, "", err
			}
		}

		if resp == nil || len(resp.Reservations) == 0 || len(resp.Reservations[0].Instances) == 0 {
			// Sometimes AWS just has consistency issues and doesn't see
			// our instance yet. Return an empty state.
			return nil, "", nil
		}

		i = &resp.Reservations[0].Instances[0]
		return i, i.State.Name, nil
	}
}
開發者ID:hnakamur,項目名稱:packer,代碼行數:28,代碼來源:state.go

示例7: testAccCheckInternetGatewayDestroy

func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
	conn := testAccProvider.ec2conn

	for _, rs := range s.Resources {
		if rs.Type != "aws_internet_gateway" {
			continue
		}

		// Try to find the resource
		resp, err := conn.DescribeInternetGateways(
			[]string{rs.ID}, ec2.NewFilter())
		if err == nil {
			if len(resp.InternetGateways) > 0 {
				return fmt.Errorf("still exist.")
			}

			return nil
		}

		// Verify the error is what we want
		ec2err, ok := err.(*ec2.Error)
		if !ok {
			return err
		}
		if ec2err.Code != "InvalidInternetGatewayID.NotFound" {
			return err
		}
	}

	return nil
}
開發者ID:EZTABLE,項目名稱:terraform,代碼行數:31,代碼來源:resource_aws_internet_gateway_test.go

示例8: FindShip

func (client *Client) FindShip(name string) types.Ship {
	var ship types.Ship

	filter := ec2.NewFilter()
	filter.Add("tag-key", "docker")
	filter.Add("tag:Name", name)

	for _, region := range client.region {
		response, _ := region.Instances(nil, filter)
		for _, pool := range response.Reservations {
			for _, instance := range pool.Instances {
				ship = types.Ship{
					instance.InstanceId,
					client.SearchTag(instance.Tags, "Name"),
					instance.DNSName,
					instance.PublicIpAddress,
					client.State(instance.State),
					"Ubuntu 14.04",
					instance.InstanceType,
					27017,
					"http",
					0,
					nil,
					false,
				}
			}
		}

	}

	return ship
}
開發者ID:krane-io,項目名稱:krane,代碼行數:32,代碼來源:aws.go

示例9: 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)

	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, []ec2.SecurityGroup{{Name: "default", Id: "sg-67ad940e"}})
	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.AvailZone, Equals, "us-east-1b")
}
開發者ID:ericcapricorn,項目名稱:kubernetes,代碼行數:31,代碼來源:ec2_test.go

示例10: testAccCheckInternetGatewayExists

func testAccCheckInternetGatewayExists(n string, ig *ec2.InternetGateway) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		rs, ok := s.Resources[n]
		if !ok {
			return fmt.Errorf("Not found: %s", n)
		}

		if rs.ID == "" {
			return fmt.Errorf("No ID is set")
		}

		conn := testAccProvider.ec2conn
		resp, err := conn.DescribeInternetGateways(
			[]string{rs.ID}, ec2.NewFilter())
		if err != nil {
			return err
		}
		if len(resp.InternetGateways) == 0 {
			return fmt.Errorf("InternetGateway not found")
		}

		*ig = resp.InternetGateways[0]

		return nil
	}
}
開發者ID:EZTABLE,項目名稱:terraform,代碼行數:26,代碼來源:resource_aws_internet_gateway_test.go

示例11: testAccCheckVpcExists

func testAccCheckVpcExists(n string, vpc *ec2.VPC) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		rs, ok := s.Resources[n]
		if !ok {
			return fmt.Errorf("Not found: %s", n)
		}

		if rs.ID == "" {
			return fmt.Errorf("No VPC ID is set")
		}

		conn := testAccProvider.ec2conn
		resp, err := conn.DescribeVpcs([]string{rs.ID}, ec2.NewFilter())
		if err != nil {
			return err
		}
		if len(resp.VPCs) == 0 {
			return fmt.Errorf("VPC not found")
		}

		*vpc = resp.VPCs[0]

		return nil
	}
}
開發者ID:GeorgeErickson,項目名稱:terraform-1,代碼行數:25,代碼來源:resource_aws_vpc_test.go

示例12: Run

func (s *StepSourceAMIInfo) Run(state multistep.StateBag) multistep.StepAction {
	ec2conn := state.Get("ec2").(*ec2.EC2)
	ui := state.Get("ui").(packer.Ui)

	ui.Say("Inspecting the source AMI...")
	imageResp, err := ec2conn.Images([]string{s.SourceAmi}, ec2.NewFilter())
	if err != nil {
		err := fmt.Errorf("Error querying AMI: %s", err)
		state.Put("error", err)
		ui.Error(err.Error())
		return multistep.ActionHalt
	}

	if len(imageResp.Images) == 0 {
		err := fmt.Errorf("Source AMI '%s' was not found!", s.SourceAmi)
		state.Put("error", err)
		ui.Error(err.Error())
		return multistep.ActionHalt
	}

	image := &imageResp.Images[0]

	// Enhanced Networking (SriovNetSupport) can only be enabled on HVM AMIs.
	// See http://goo.gl/icuXh5
	if s.EnhancedNetworking && image.VirtualizationType != "hvm" {
		err := fmt.Errorf("Cannot enable enhanced networking, source AMI '%s' is not HVM", s.SourceAmi)
		state.Put("error", err)
		ui.Error(err.Error())
		return multistep.ActionHalt
	}

	state.Put("source_image", image)
	return multistep.ActionContinue
}
開發者ID:JNPRAutomate,項目名稱:packer,代碼行數:34,代碼來源:step_source_ami_info.go

示例13: Run

func (s *StepSourceAMIInfo) Run(state map[string]interface{}) multistep.StepAction {
	config := state["config"].(*Config)
	ec2conn := state["ec2"].(*ec2.EC2)
	ui := state["ui"].(packer.Ui)

	ui.Say("Inspecting the source AMI...")
	imageResp, err := ec2conn.Images([]string{config.SourceAmi}, ec2.NewFilter())
	if err != nil {
		err := fmt.Errorf("Error querying AMI: %s", err)
		state["error"] = err
		ui.Error(err.Error())
		return multistep.ActionHalt
	}

	if len(imageResp.Images) == 0 {
		err := fmt.Errorf("Source AMI '%s' was not found!", config.SourceAmi)
		state["error"] = err
		ui.Error(err.Error())
		return multistep.ActionHalt
	}

	image := &imageResp.Images[0]

	// It must be EBS-backed otherwise the build won't work
	if image.RootDeviceType != "ebs" {
		err := fmt.Errorf("The root device of the source AMI must be EBS-backed.")
		state["error"] = err
		ui.Error(err.Error())
		return multistep.ActionHalt
	}

	state["source_image"] = image
	return multistep.ActionContinue
}
開發者ID:ramonvanalteren,項目名稱:packer,代碼行數:34,代碼來源:step_source_ami_info.go

示例14: testAccCheckRouteTableAssociationDestroy

func testAccCheckRouteTableAssociationDestroy(s *terraform.State) error {
	conn := testAccProvider.Meta().(*AWSClient).ec2conn

	for _, rs := range s.RootModule().Resources {
		if rs.Type != "aws_route_table_association" {
			continue
		}

		// Try to find the resource
		resp, err := conn.DescribeRouteTables(
			[]string{rs.Primary.Attributes["route_table_Id"]}, ec2.NewFilter())
		if err != nil {
			// Verify the error is what we want
			ec2err, ok := err.(*ec2.Error)
			if !ok {
				return err
			}
			if ec2err.Code != "InvalidRouteTableID.NotFound" {
				return err
			}
			return nil
		}

		rt := resp.RouteTables[0]
		if len(rt.Associations) > 0 {
			return fmt.Errorf(
				"route table %s has associations", rt.RouteTableId)

		}
	}

	return nil
}
開發者ID:packetloop,項目名稱:terraform,代碼行數:33,代碼來源:resource_aws_route_table_association_test.go

示例15: SSHAddress

// SSHAddress returns a function that can be given to the SSH communicator
// for determining the SSH address based on the instance DNS name.
func SSHAddress(e *ec2.EC2, port int) func(multistep.StateBag) (string, error) {
	return func(state multistep.StateBag) (string, error) {
		for j := 0; j < 2; j++ {
			var host string
			i := state.Get("instance").(*ec2.Instance)
			if i.DNSName != "" {
				host = i.DNSName
			} else if i.VpcId != "" {
				if i.PublicIpAddress != "" {
					host = i.PublicIpAddress
				} else {
					host = i.PrivateIpAddress
				}
			}

			if host != "" {
				return fmt.Sprintf("%s:%d", host, port), nil
			}

			r, err := e.Instances([]string{i.InstanceId}, ec2.NewFilter())
			if err != nil {
				return "", err
			}

			if len(r.Reservations) == 0 || len(r.Reservations[0].Instances) == 0 {
				return "", fmt.Errorf("instance not found: %s", i.InstanceId)
			}

			state.Put("instance", &r.Reservations[0].Instances[0])
			time.Sleep(1 * time.Second)
		}

		return "", errors.New("couldn't determine IP address for instance")
	}
}
開發者ID:EdevMosaic,項目名稱:packer,代碼行數:37,代碼來源:ssh.go


注:本文中的github.com/mitchellh/goamz/ec2.NewFilter函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。