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


Golang secgroups.Get函數代碼示例

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


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

示例1: resourceComputeSecGroupV2Read

func resourceComputeSecGroupV2Read(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)
	computeClient, err := config.computeV2Client(d.Get("region").(string))
	if err != nil {
		return fmt.Errorf("Error creating OpenStack compute client: %s", err)
	}

	sg, err := secgroups.Get(computeClient, d.Id()).Extract()
	if err != nil {
		return CheckDeleted(d, err, "security group")
	}

	d.Set("name", sg.Name)
	d.Set("description", sg.Description)
	rtm := rulesToMap(sg.Rules)
	for _, v := range rtm {
		if v["group"] == d.Get("name") {
			v["self"] = "1"
		} else {
			v["self"] = "0"
		}
	}
	log.Printf("[DEBUG] rulesToMap(sg.Rules): %+v", rtm)
	d.Set("rule", rtm)

	return nil
}
開發者ID:semarj,項目名稱:terraform,代碼行數:27,代碼來源:resource_openstack_compute_secgroup_v2.go

示例2: testAccCheckComputeV2SecGroupExists

func testAccCheckComputeV2SecGroupExists(t *testing.T, n string, secgroup *secgroups.SecurityGroup) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		rs, ok := s.RootModule().Resources[n]
		if !ok {
			return fmt.Errorf("Not found: %s", n)
		}

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

		config := testAccProvider.Meta().(*Config)
		computeClient, err := config.computeV2Client(OS_REGION_NAME)
		if err != nil {
			return fmt.Errorf("(testAccCheckComputeV2SecGroupExists) Error creating OpenStack compute client: %s", err)
		}

		found, err := secgroups.Get(computeClient, rs.Primary.ID).Extract()
		if err != nil {
			return err
		}

		if found.ID != rs.Primary.ID {
			return fmt.Errorf("Security group not found")
		}

		*secgroup = *found

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

示例3: testAccCheckComputeV2SecGroupDestroy

func testAccCheckComputeV2SecGroupDestroy(s *terraform.State) error {
	config := testAccProvider.Meta().(*Config)
	computeClient, err := config.computeV2Client(OS_REGION_NAME)
	if err != nil {
		return fmt.Errorf("(testAccCheckComputeV2SecGroupDestroy) Error creating OpenStack compute client: %s", err)
	}

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

		_, err := secgroups.Get(computeClient, rs.Primary.ID).Extract()
		if err == nil {
			return fmt.Errorf("Security group still exists")
		}
	}

	return nil
}
開發者ID:Zordrak,項目名稱:terraform,代碼行數:20,代碼來源:resource_openstack_compute_secgroup_v2_test.go

示例4: SecGroupV2StateRefreshFunc

func SecGroupV2StateRefreshFunc(computeClient *gophercloud.ServiceClient, d *schema.ResourceData) resource.StateRefreshFunc {
	return func() (interface{}, string, error) {
		log.Printf("[DEBUG] Attempting to delete Security Group %s.\n", d.Id())

		err := secgroups.Delete(computeClient, d.Id()).ExtractErr()
		if err != nil {
			return nil, "", err
		}

		s, err := secgroups.Get(computeClient, d.Id()).Extract()
		if err != nil {
			err = CheckDeleted(d, err, "Security Group")
			if err != nil {
				return s, "", err
			} else {
				log.Printf("[DEBUG] Successfully deleted Security Group %s", d.Id())
				return s, "DELETED", nil
			}
		}

		log.Printf("[DEBUG] Security Group %s still active.\n", d.Id())
		return s, "ACTIVE", nil
	}
}
開發者ID:chandy,項目名稱:terraform,代碼行數:24,代碼來源:resource_openstack_compute_secgroup_v2.go

示例5: getSecGroup

func getSecGroup(t *testing.T, client *gophercloud.ServiceClient, id string) {
	group, err := secgroups.Get(client, id).Extract()
	th.AssertNoErr(t, err)

	t.Logf("Getting %s: %#v", id, group)
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:6,代碼來源:secgroup_test.go


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