本文整理汇总了Golang中github.com/rackspace/gophercloud/openstack/networking/v2/subnets.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: resourceNetworkingSubnetV2Read
func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
s, err := subnets.Get(networkingClient, d.Id()).Extract()
if err != nil {
return CheckDeleted(d, err, "subnet")
}
log.Printf("[DEBUG] Retreived Subnet %s: %+v", d.Id(), s)
d.Set("newtork_id", s.NetworkID)
d.Set("cidr", s.CIDR)
d.Set("ip_version", s.IPVersion)
d.Set("name", s.Name)
d.Set("tenant_id", s.TenantID)
d.Set("allocation_pools", s.AllocationPools)
d.Set("gateway_ip", s.GatewayIP)
d.Set("enable_dhcp", s.EnableDHCP)
d.Set("dns_nameservers", s.DNSNameservers)
d.Set("host_routes", s.HostRoutes)
return nil
}
开发者ID:discogestalt,项目名称:terraform,代码行数:27,代码来源:resource_openstack_networking_subnet_v2.go
示例2: waitForSubnetDelete
func waitForSubnetDelete(networkingClient *gophercloud.ServiceClient, subnetId string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
log.Printf("[DEBUG] Attempting to delete OpenStack Subnet %s.\n", subnetId)
s, err := subnets.Get(networkingClient, subnetId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return s, "ACTIVE", err
}
if errCode.Actual == 404 {
log.Printf("[DEBUG] Successfully deleted OpenStack Subnet %s", subnetId)
return s, "DELETED", nil
}
}
err = subnets.Delete(networkingClient, subnetId).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return s, "ACTIVE", err
}
if errCode.Actual == 404 {
log.Printf("[DEBUG] Successfully deleted OpenStack Subnet %s", subnetId)
return s, "DELETED", nil
}
}
log.Printf("[DEBUG] OpenStack Subnet %s still active.\n", subnetId)
return s, "ACTIVE", nil
}
}
开发者ID:discogestalt,项目名称:terraform,代码行数:32,代码来源:resource_openstack_networking_subnet_v2.go
示例3: testAccCheckNetworkingV2SubnetExists
func testAccCheckNetworkingV2SubnetExists(t *testing.T, n string, subnet *subnets.Subnet) 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)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil {
return fmt.Errorf("(testAccCheckNetworkingV2SubnetExists) Error creating OpenStack networking client: %s", err)
}
found, err := subnets.Get(networkingClient, rs.Primary.ID).Extract()
if err != nil {
return err
}
if found.ID != rs.Primary.ID {
return fmt.Errorf("Subnet not found")
}
*subnet = *found
return nil
}
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:31,代码来源:resource_openstack_networking_subnet_v2_test.go
示例4: waitForSubnetActive
func waitForSubnetActive(networkingClient *gophercloud.ServiceClient, subnetId string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
s, err := subnets.Get(networkingClient, subnetId).Extract()
if err != nil {
return nil, "", err
}
log.Printf("[DEBUG] OpenStack Neutron Subnet: %+v", s)
return s, "ACTIVE", nil
}
}
开发者ID:discogestalt,项目名称:terraform,代码行数:11,代码来源:resource_openstack_networking_subnet_v2.go
示例5: TestCRUD
func TestCRUD(t *testing.T) {
Setup(t)
defer Teardown()
// Setup network
t.Log("Setting up network")
n, err := networks.Create(Client, networks.CreateOpts{Name: "tmp_network", AdminStateUp: networks.Up}).Extract()
th.AssertNoErr(t, err)
networkID := n.ID
defer networks.Delete(Client, networkID)
// Create subnet
t.Log("Create subnet")
enable := false
opts := subnets.CreateOpts{
NetworkID: networkID,
CIDR: "192.168.199.0/24",
IPVersion: subnets.IPv4,
Name: "my_subnet",
EnableDHCP: &enable,
}
s, err := subnets.Create(Client, opts).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.NetworkID, networkID)
th.AssertEquals(t, s.CIDR, "192.168.199.0/24")
th.AssertEquals(t, s.IPVersion, 4)
th.AssertEquals(t, s.Name, "my_subnet")
th.AssertEquals(t, s.EnableDHCP, false)
subnetID := s.ID
// Get subnet
t.Log("Getting subnet")
s, err = subnets.Get(Client, subnetID).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.ID, subnetID)
// Update subnet
t.Log("Update subnet")
s, err = subnets.Update(Client, subnetID, subnets.UpdateOpts{Name: "new_subnet_name"}).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.Name, "new_subnet_name")
// Delete subnet
t.Log("Delete subnet")
res := subnets.Delete(Client, subnetID)
th.AssertNoErr(t, res.Err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:48,代码来源:subnet_test.go
示例6: testAccCheckNetworkingV2SubnetDestroy
func testAccCheckNetworkingV2SubnetDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil {
return fmt.Errorf("(testAccCheckNetworkingV2SubnetDestroy) Error creating OpenStack networking client: %s", err)
}
for _, rs := range s.RootModule().Resources {
if rs.Type != "openstack_networking_subnet_v2" {
continue
}
_, err := subnets.Get(networkingClient, rs.Primary.ID).Extract()
if err == nil {
return fmt.Errorf("Subnet still exists")
}
}
return nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:20,代码来源:resource_openstack_networking_subnet_v2_test.go
示例7: TestSubnetCRUD
func TestSubnetCRUD(t *testing.T) {
Setup(t)
defer Teardown()
// Setup network
t.Log("Setting up network")
n, err := networks.Create(Client, networks.CreateOpts{Name: "tmp_network", AdminStateUp: networks.Up}).Extract()
th.AssertNoErr(t, err)
networkID := n.ID
defer networks.Delete(Client, networkID)
// Create subnet
t.Log("Create subnet")
enable := false
opts := subnets.CreateOpts{
NetworkID: networkID,
CIDR: "192.168.199.0/24",
IPVersion: subnets.IPv4,
Name: "my_subnet",
EnableDHCP: &enable,
}
s, err := subnets.Create(Client, opts).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.NetworkID, networkID)
th.AssertEquals(t, s.CIDR, "192.168.199.0/24")
th.AssertEquals(t, s.IPVersion, 4)
th.AssertEquals(t, s.Name, "my_subnet")
th.AssertEquals(t, s.EnableDHCP, false)
th.AssertEquals(t, s.GatewayIP, "192.168.199.1")
subnetID := s.ID
// Get subnet
t.Log("Getting subnet")
s, err = subnets.Get(Client, subnetID).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.ID, subnetID)
// Update subnet
t.Log("Update subnet")
s, err = subnets.Update(Client, subnetID, subnets.UpdateOpts{Name: "new_subnet_name"}).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.Name, "new_subnet_name")
// Delete subnet
t.Log("Delete subnet")
res := subnets.Delete(Client, subnetID)
th.AssertNoErr(t, res.Err)
// Create subnet with no gateway
t.Log("Create subnet with no gateway")
opts = subnets.CreateOpts{
NetworkID: networkID,
CIDR: "192.168.199.0/24",
IPVersion: subnets.IPv4,
Name: "my_subnet",
EnableDHCP: &enable,
NoGateway: true,
}
s, err = subnets.Create(Client, opts).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.NetworkID, networkID)
th.AssertEquals(t, s.CIDR, "192.168.199.0/24")
th.AssertEquals(t, s.IPVersion, 4)
th.AssertEquals(t, s.Name, "my_subnet")
th.AssertEquals(t, s.EnableDHCP, false)
th.AssertEquals(t, s.GatewayIP, "")
subnetID = s.ID
// Get subnet
t.Log("Getting subnet with no gateway")
s, err = subnets.Get(Client, subnetID).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.ID, subnetID)
// Update subnet
t.Log("Update subnet with no gateway")
s, err = subnets.Update(Client, subnetID, subnets.UpdateOpts{Name: "new_subnet_name"}).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.Name, "new_subnet_name")
// Delete subnet
t.Log("Delete subnet with no gateway")
res = subnets.Delete(Client, subnetID)
th.AssertNoErr(t, res.Err)
// Create subnet with invalid gateway configuration
t.Log("Create subnet with invalid gateway configuration")
opts = subnets.CreateOpts{
NetworkID: networkID,
CIDR: "192.168.199.0/24",
IPVersion: subnets.IPv4,
Name: "my_subnet",
EnableDHCP: &enable,
NoGateway: true,
GatewayIP: "192.168.199.1",
}
_, err = subnets.Create(Client, opts).Extract()
if err == nil {
//.........这里部分代码省略.........
开发者ID:sstrato,项目名称:gophercloud,代码行数:101,代码来源:subnet_test.go
示例8: Get
// Get retrieves a specific subnet based on its unique ID.
func Get(c *gophercloud.ServiceClient, networkID string) os.GetResult {
return os.Get(c, networkID)
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:4,代码来源:delegate.go
注:本文中的github.com/rackspace/gophercloud/openstack/networking/v2/subnets.Get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论