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


Golang Instance.PrivateIPAddress方法代码示例

本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/ec2.Instance.PrivateIPAddress方法的典型用法代码示例。如果您正苦于以下问题:Golang Instance.PrivateIPAddress方法的具体用法?Golang Instance.PrivateIPAddress怎么用?Golang Instance.PrivateIPAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/aws/aws-sdk-go/service/ec2.Instance的用法示例。


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

示例1: TestNodeAddresses

func TestNodeAddresses(t *testing.T) {
	// Note these instances have the same name
	// (we test that this produces an error)
	var instance0 ec2.Instance
	var instance1 ec2.Instance

	//0
	instance0.InstanceID = aws.String("instance-same")
	instance0.PrivateDNSName = aws.String("instance-same.ec2.internal")
	instance0.PrivateIPAddress = aws.String("192.168.0.1")
	instance0.PublicIPAddress = aws.String("1.2.3.4")
	instance0.InstanceType = aws.String("c3.large")
	state0 := ec2.InstanceState{
		Name: aws.String("running"),
	}
	instance0.State = &state0

	//1
	instance1.InstanceID = aws.String("instance-same")
	instance1.PrivateDNSName = aws.String("instance-same.ec2.internal")
	instance1.PrivateIPAddress = aws.String("192.168.0.2")
	instance1.InstanceType = aws.String("c3.large")
	state1 := ec2.InstanceState{
		Name: aws.String("running"),
	}
	instance1.State = &state1

	instances := []*ec2.Instance{&instance0, &instance1}

	aws1 := mockInstancesResp([]*ec2.Instance{})
	_, err1 := aws1.NodeAddresses("instance-mismatch.ec2.internal")
	if err1 == nil {
		t.Errorf("Should error when no instance found")
	}

	aws2 := mockInstancesResp(instances)
	_, err2 := aws2.NodeAddresses("instance-same.ec2.internal")
	if err2 == nil {
		t.Errorf("Should error when multiple instances found")
	}

	aws3 := mockInstancesResp(instances[0:1])
	addrs3, err3 := aws3.NodeAddresses("instance-same.ec2.internal")
	if err3 != nil {
		t.Errorf("Should not error when instance found")
	}
	if len(addrs3) != 3 {
		t.Errorf("Should return exactly 3 NodeAddresses")
	}
	testHasNodeAddress(t, addrs3, api.NodeInternalIP, "192.168.0.1")
	testHasNodeAddress(t, addrs3, api.NodeLegacyHostIP, "192.168.0.1")
	testHasNodeAddress(t, addrs3, api.NodeExternalIP, "1.2.3.4")
}
开发者ID:shrids,项目名称:kubernetes,代码行数:53,代码来源:aws_test.go


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