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


Golang os.Instances函數代碼示例

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


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

示例1: TestInstances

func TestInstances(t *testing.T) {
	cfg, ok := configFromEnv()
	if !ok {
		t.Skipf("No config found in environment")
	}

	os, err := newRackspace(cfg)
	if err != nil {
		t.Fatalf("Failed to construct/authenticate Rackspace: %s", err)
	}

	i, ok := os.Instances()
	if !ok {
		t.Fatalf("Instances() returned false")
	}

	srvs, err := i.List(".")
	if err != nil {
		t.Fatalf("Instances.List() failed: %s", err)
	}
	if len(srvs) == 0 {
		t.Fatalf("Instances.List() returned zero servers")
	}
	t.Logf("Found servers (%d): %s\n", len(srvs), srvs)

	addrs, err := i.NodeAddresses(srvs[0])
	if err != nil {
		t.Fatalf("Instances.NodeAddresses(%s) failed: %s", srvs[0], err)
	}
	t.Logf("Found NodeAddresses(%s) = %s\n", srvs[0], addrs)
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:31,代碼來源:rackspace_test.go

示例2: TestInstances

func TestInstances(t *testing.T) {
	cfg, ok := configFromEnv()
	if !ok {
		t.Skipf("No config found in environment")
	}

	os, err := newOpenStack(cfg)
	if err != nil {
		t.Fatalf("Failed to construct/authenticate OpenStack: %s", err)
	}

	i, ok := os.Instances()
	if !ok {
		t.Fatalf("Instances() returned false")
	}

	srvs, err := i.List(".")
	if err != nil {
		t.Fatalf("Instances.List() failed: %s", err)
	}
	if len(srvs) == 0 {
		t.Fatalf("Instances.List() returned zero servers")
	}
	t.Logf("Found servers (%d): %s\n", len(srvs), srvs)

	srvExternalId, err := i.ExternalID(srvs[0])
	if err != nil {
		t.Fatalf("Instances.ExternalId(%s) failed: %s", srvs[0], err)
	}
	t.Logf("Found server (%s), with external id: %s\n", srvs[0], srvExternalId)

	srvInstanceId, err := i.InstanceID(srvs[0])
	if err != nil {
		t.Fatalf("Instance.InstanceId(%s) failed: %s", srvs[0], err)
	}
	t.Logf("Found server (%s), with instance id: %s\n", srvs[0], srvInstanceId)

	addrs, err := i.NodeAddresses(srvs[0])
	if err != nil {
		t.Fatalf("Instances.NodeAddresses(%s) failed: %s", srvs[0], err)
	}
	t.Logf("Found NodeAddresses(%s) = %s\n", srvs[0], addrs)
}
開發者ID:nak3,項目名稱:kubernetes,代碼行數:43,代碼來源:openstack_test.go

示例3: TestInstances

func TestInstances(t *testing.T) {
	cfg, ok := configFromEnv()
	if !ok {
		t.Skipf("No config found in environment")
	}

	os, err := newOpenStack(cfg)
	if err != nil {
		t.Fatalf("Failed to construct/authenticate OpenStack: %s", err)
	}

	i, ok := os.Instances()
	if !ok {
		t.Fatalf("Instances() returned false")
	}

	srvs, err := i.List(".")
	if err != nil {
		t.Fatalf("Instances.List() failed: %s", err)
	}
	if len(srvs) == 0 {
		t.Fatalf("Instances.List() returned zero servers")
	}
	t.Logf("Found servers (%d): %s\n", len(srvs), srvs)

	ip, err := i.IPAddress(srvs[0])
	if err != nil {
		t.Fatalf("Instances.IPAddress(%s) failed: %s", srvs[0], err)
	}
	t.Logf("Found IPAddress(%s) = %s\n", srvs[0], ip)

	rsrcs, err := i.GetNodeResources(srvs[0])
	if err != nil {
		t.Fatalf("Instances.GetNodeResources(%s) failed: %s", srvs[0], err)
	}
	t.Logf("Found GetNodeResources(%s) = %s\n", srvs[0], rsrcs)
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:37,代碼來源:openstack_test.go


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