本文整理汇总了Golang中github.com/rackspace/gophercloud/openstack/networking/v2/ports.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestPortCRUD
func TestPortCRUD(t *testing.T) {
Setup(t)
defer Teardown()
// Setup network
t.Log("Setting up network")
networkID, err := createNetwork()
th.AssertNoErr(t, err)
defer networks.Delete(Client, networkID)
// Setup subnet
t.Logf("Setting up subnet on network %s", networkID)
subnetID, err := createSubnet(networkID)
th.AssertNoErr(t, err)
defer subnets.Delete(Client, subnetID)
// Create port
t.Logf("Create port based on subnet %s", subnetID)
portID := createPort(t, networkID, subnetID)
// List ports
t.Logf("Listing all ports")
listPorts(t)
// Get port
if portID == "" {
t.Fatalf("In order to retrieve a port, the portID must be set")
}
p, err := ports.Get(Client, portID).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, p.ID, portID)
// Update port
updateOpts := ports.UpdateOpts{
Name: "new_port_name",
AllowedAddressPairs: []ports.AddressPair{
ports.AddressPair{IPAddress: "192.168.199.201"},
},
}
p, err = ports.Update(Client, portID, updateOpts).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, p.Name, "new_port_name")
updatedPort, err := ports.Get(Client, portID).Extract()
th.AssertEquals(t, updatedPort.AllowedAddressPairs[0].IPAddress, "192.168.199.201")
// Delete port
res := ports.Delete(Client, portID)
th.AssertNoErr(t, res.Err)
}
示例2: testAccCheckNetworkingV2RouterInterfaceExists
func testAccCheckNetworkingV2RouterInterfaceExists(t *testing.T, n string) 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("(testAccCheckNetworkingV2RouterInterfaceExists) Error creating OpenStack networking client: %s", err)
}
found, err := ports.Get(networkingClient, rs.Primary.ID).Extract()
if err != nil {
return err
}
if found.ID != rs.Primary.ID {
return fmt.Errorf("Router interface not found")
}
return nil
}
}
开发者ID:AssertSelenium,项目名称:terraform,代码行数:29,代码来源:resource_openstack_networking_router_interface_v2_test.go
示例3: waitForNetworkPortDelete
func waitForNetworkPortDelete(networkingClient *gophercloud.ServiceClient, portId string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
log.Printf("[DEBUG] Attempting to delete OpenStack Neutron Port %s", portId)
p, err := ports.Get(networkingClient, portId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return p, "ACTIVE", err
}
if errCode.Actual == 404 {
log.Printf("[DEBUG] Successfully deleted OpenStack Port %s", portId)
return p, "DELETED", nil
}
}
err = ports.Delete(networkingClient, portId).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return p, "ACTIVE", err
}
if errCode.Actual == 404 {
log.Printf("[DEBUG] Successfully deleted OpenStack Port %s", portId)
return p, "DELETED", nil
}
}
log.Printf("[DEBUG] OpenStack Port %s still active.\n", portId)
return p, "ACTIVE", nil
}
}
示例4: resourceNetworkingPortV2Read
func resourceNetworkingPortV2Read(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)
}
p, err := ports.Get(networkingClient, d.Id()).Extract()
if err != nil {
return CheckDeleted(d, err, "port")
}
log.Printf("[DEBUG] Retreived Port %s: %+v", d.Id(), p)
d.Set("name", p.Name)
d.Set("admin_state_up", p.AdminStateUp)
d.Set("network_id", p.NetworkID)
d.Set("mac_address", p.MACAddress)
d.Set("tenant_id", p.TenantID)
d.Set("device_owner", p.DeviceOwner)
d.Set("security_group_ids", p.SecurityGroups)
d.Set("device_id", p.DeviceID)
d.Set("fixed_ip", p.FixedIPs)
return nil
}
示例5: resourceNetworkingRouterInterfaceV2Read
func resourceNetworkingRouterInterfaceV2Read(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)
}
n, err := ports.Get(networkingClient, d.Id()).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return fmt.Errorf("Error retrieving OpenStack Neutron Router Interface: %s", err)
}
if httpError.Actual == 404 {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving OpenStack Neutron Router Interface: %s", err)
}
log.Printf("[DEBUG] Retreived Router Interface %s: %+v", d.Id(), n)
return nil
}
示例6: resourceNetworkingPortV2Read
func resourceNetworkingPortV2Read(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)
}
p, err := ports.Get(networkingClient, d.Id()).Extract()
if err != nil {
return CheckDeleted(d, err, "port")
}
log.Printf("[DEBUG] Retreived Port %s: %+v", d.Id(), p)
d.Set("name", p.Name)
d.Set("admin_state_up", p.AdminStateUp)
d.Set("network_id", p.NetworkID)
d.Set("mac_address", p.MACAddress)
d.Set("tenant_id", p.TenantID)
d.Set("device_owner", p.DeviceOwner)
d.Set("security_group_ids", p.SecurityGroups)
d.Set("device_id", p.DeviceID)
// Convert FixedIPs to list of map
var ips []map[string]interface{}
for _, ipObject := range p.FixedIPs {
ip := make(map[string]interface{})
ip["subnet_id"] = ipObject.SubnetID
ip["ip_address"] = ipObject.IPAddress
ips = append(ips, ip)
}
d.Set("fixed_ip", ips)
return nil
}
示例7: waitForRouterInterfaceActive
func waitForRouterInterfaceActive(networkingClient *gophercloud.ServiceClient, rId string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
r, err := ports.Get(networkingClient, rId).Extract()
if err != nil {
return nil, "", err
}
log.Printf("[DEBUG] OpenStack Neutron Router Interface: %+v", r)
return r, r.Status, nil
}
}
示例8: waitForNetworkPortActive
func waitForNetworkPortActive(networkingClient *gophercloud.ServiceClient, portId string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
p, err := ports.Get(networkingClient, portId).Extract()
if err != nil {
return nil, "", err
}
log.Printf("[DEBUG] OpenStack Neutron Port: %+v", p)
if p.Status == "DOWN" || p.Status == "ACTIVE" {
return p, "ACTIVE", nil
}
return p, p.Status, nil
}
}
示例9: testAccCheckNetworkingV2RouterInterfaceDestroy
func testAccCheckNetworkingV2RouterInterfaceDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil {
return fmt.Errorf("(testAccCheckNetworkingV2RouterInterfaceDestroy) Error creating OpenStack networking client: %s", err)
}
for _, rs := range s.RootModule().Resources {
if rs.Type != "openstack_networking_router_interface_v2" {
continue
}
_, err := ports.Get(networkingClient, rs.Primary.ID).Extract()
if err == nil {
return fmt.Errorf("Router interface still exists")
}
}
return nil
}
开发者ID:AssertSelenium,项目名称:terraform,代码行数:20,代码来源:resource_openstack_networking_router_interface_v2_test.go
示例10: waitForRouterInterfaceDelete
func waitForRouterInterfaceDelete(networkingClient *gophercloud.ServiceClient, d *schema.ResourceData) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
routerId := d.Get("router_id").(string)
routerInterfaceId := d.Id()
log.Printf("[DEBUG] Attempting to delete OpenStack Router Interface %s.\n", routerInterfaceId)
removeOpts := routers.InterfaceOpts{
SubnetID: d.Get("subnet_id").(string),
PortID: d.Get("port_id").(string),
}
r, err := ports.Get(networkingClient, routerInterfaceId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return r, "ACTIVE", err
}
if errCode.Actual == 404 {
log.Printf("[DEBUG] Successfully deleted OpenStack Router Interface %s", routerInterfaceId)
return r, "DELETED", nil
}
}
_, err = routers.RemoveInterface(networkingClient, routerId, removeOpts).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return r, "ACTIVE", err
}
if errCode.Actual == 404 {
log.Printf("[DEBUG] Successfully deleted OpenStack Router Interface %s", routerInterfaceId)
return r, "DELETED", nil
}
}
log.Printf("[DEBUG] OpenStack Router Interface %s still active.\n", routerInterfaceId)
return r, "ACTIVE", nil
}
}
示例11: Get
// Get retrieves a specific port based on its unique ID.
func Get(c *gophercloud.ServiceClient, networkID string) os.GetResult {
return os.Get(c, networkID)
}