本文整理汇总了Golang中github.com/gophercloud/gophercloud/openstack/networking/v2/ports.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Port %s", portId)
return p, "DELETED", nil
}
return p, "ACTIVE", err
}
err = ports.Delete(networkingClient, portId).ExtractErr()
if err != nil {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Port %s", portId)
return p, "DELETED", nil
}
return p, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack Port %s still active.\n", portId)
return p, "ACTIVE", nil
}
}
开发者ID:mhlias,项目名称:terraform,代码行数:26,代码来源:resource_openstack_networking_port_v2.go
示例2: testAccCheckNetworkingV2PortExists
func testAccCheckNetworkingV2PortExists(t *testing.T, n string, port *ports.Port) 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("(testAccCheckNetworkingV2PortExists) 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("Port not found")
}
*port = *found
return nil
}
}
开发者ID:paultyng,项目名称:terraform,代码行数:31,代码来源:resource_openstack_networking_port_v2_test.go
示例3: CreatePort
// CreatePort will create a port on the specified subnet. An error will be
// returned if the port could not be created.
func CreatePort(t *testing.T, client *gophercloud.ServiceClient, networkID, subnetID string) (*ports.Port, error) {
portName := tools.RandomString("TESTACC-", 8)
t.Logf("Attempting to create port: %s", portName)
createOpts := ports.CreateOpts{
NetworkID: networkID,
Name: portName,
AdminStateUp: gophercloud.Enabled,
FixedIPs: []ports.IP{ports.IP{SubnetID: subnetID}},
}
port, err := ports.Create(client, createOpts).Extract()
if err != nil {
return port, err
}
if err := WaitForPortToCreate(client, port.ID, 60); err != nil {
return port, err
}
newPort, err := ports.Get(client, port.ID).Extract()
if err != nil {
return newPort, err
}
t.Logf("Successfully created port: %s", portName)
return newPort, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:32,代码来源:networking.go
示例4: 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
}
}
开发者ID:hooklift,项目名称:terraform,代码行数:11,代码来源:resource_openstack_networking_router_interface_v2.go
示例5: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/ports/46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"port": {
"status": "ACTIVE",
"name": "",
"admin_state_up": true,
"network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7",
"tenant_id": "7e02058126cc4950b75f9970368ba177",
"device_owner": "network:router_interface",
"mac_address": "fa:16:3e:23:fd:d7",
"fixed_ips": [
{
"subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2",
"ip_address": "10.0.0.1"
}
],
"id": "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2",
"security_groups": [],
"device_id": "5e3898d7-11be-483e-9732-b2f5eccd2b2e"
}
}
`)
})
n, err := ports.Get(fake.ServiceClient(), "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.Status, "ACTIVE")
th.AssertEquals(t, n.Name, "")
th.AssertEquals(t, n.AdminStateUp, true)
th.AssertEquals(t, n.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7")
th.AssertEquals(t, n.TenantID, "7e02058126cc4950b75f9970368ba177")
th.AssertEquals(t, n.DeviceOwner, "network:router_interface")
th.AssertEquals(t, n.MACAddress, "fa:16:3e:23:fd:d7")
th.AssertDeepEquals(t, n.FixedIPs, []ports.IP{
{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.1"},
})
th.AssertEquals(t, n.ID, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2")
th.AssertDeepEquals(t, n.SecurityGroups, []string{})
th.AssertEquals(t, n.Status, "ACTIVE")
th.AssertEquals(t, n.DeviceID, "5e3898d7-11be-483e-9732-b2f5eccd2b2e")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:53,代码来源:requests_test.go
示例6: WaitForPortToCreate
func WaitForPortToCreate(client *gophercloud.ServiceClient, portID string, secs int) error {
return gophercloud.WaitFor(secs, func() (bool, error) {
p, err := ports.Get(client, portID).Extract()
if err != nil {
return false, err
}
if p.Status == "ACTIVE" || p.Status == "DOWN" {
return true, nil
}
return false, nil
})
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:14,代码来源:networking.go
示例7: WaitForRouterInterfaceToAttach
func WaitForRouterInterfaceToAttach(client *gophercloud.ServiceClient, routerInterfaceID string, secs int) error {
return gophercloud.WaitFor(secs, func() (bool, error) {
r, err := ports.Get(client, routerInterfaceID).Extract()
if err != nil {
return false, err
}
if r.Status == "ACTIVE" {
return true, nil
}
return false, nil
})
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:14,代码来源:layer3.go
示例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
}
}
开发者ID:mhlias,项目名称:terraform,代码行数:15,代码来源:resource_openstack_networking_port_v2.go
示例9: resourceNetworkingPortV2Read
func resourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(GetRegion(d))
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] Retrieved 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)
// Convert AllowedAddressPairs to list of map
var pairs []map[string]interface{}
for _, pairObject := range p.AllowedAddressPairs {
pair := make(map[string]interface{})
pair["ip_address"] = pairObject.IPAddress
pair["mac_address"] = pairObject.MACAddress
pairs = append(pairs, pair)
}
d.Set("allowed_address_pairs", pairs)
d.Set("region", GetRegion(d))
return nil
}
开发者ID:anthcor,项目名称:terraform,代码行数:47,代码来源:resource_openstack_networking_port_v2.go
示例10: testAccCheckNetworkingV2PortDestroy
func testAccCheckNetworkingV2PortDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil {
return fmt.Errorf("(testAccCheckNetworkingV2PortDestroy) Error creating OpenStack networking client: %s", err)
}
for _, rs := range s.RootModule().Resources {
if rs.Type != "openstack_networking_port_v2" {
continue
}
_, err := ports.Get(networkingClient, rs.Primary.ID).Extract()
if err == nil {
return fmt.Errorf("Port still exists")
}
}
return nil
}
开发者ID:paultyng,项目名称:terraform,代码行数:20,代码来源:resource_openstack_networking_port_v2_test.go
示例11: 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.", routerInterfaceId)
removeOpts := routers.RemoveInterfaceOpts{
SubnetID: d.Get("subnet_id").(string),
PortID: d.Get("port_id").(string),
}
r, err := ports.Get(networkingClient, routerInterfaceId).Extract()
if err != nil {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Router Interface %s", routerInterfaceId)
return r, "DELETED", nil
}
return r, "ACTIVE", err
}
_, err = routers.RemoveInterface(networkingClient, routerId, removeOpts).Extract()
if err != nil {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Router Interface %s.", routerInterfaceId)
return r, "DELETED", nil
}
if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok {
if errCode.Actual == 409 {
log.Printf("[DEBUG] Router Interface %s is still in use.", routerInterfaceId)
return r, "ACTIVE", nil
}
}
return r, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack Router Interface %s is still active.", routerInterfaceId)
return r, "ACTIVE", nil
}
}
开发者ID:hooklift,项目名称:terraform,代码行数:41,代码来源:resource_openstack_networking_router_interface_v2.go
示例12: resourceNetworkingRouterInterfaceV2Read
func resourceNetworkingRouterInterfaceV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
n, err := ports.Get(networkingClient, d.Id()).Extract()
if err != nil {
if _, ok := err.(gophercloud.ErrDefault404); ok {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving OpenStack Neutron Router Interface: %s", err)
}
log.Printf("[DEBUG] Retrieved Router Interface %s: %+v", d.Id(), n)
return nil
}
开发者ID:hooklift,项目名称:terraform,代码行数:21,代码来源:resource_openstack_networking_router_interface_v2.go
示例13: testAccCheckLBV2LoadBalancerHasSecGroup
func testAccCheckLBV2LoadBalancerHasSecGroup(
lb *loadbalancers.LoadBalancer, sg *groups.SecGroup) resource.TestCheckFunc {
return func(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
port, err := ports.Get(networkingClient, lb.VipPortID).Extract()
if err != nil {
return err
}
for _, p := range port.SecurityGroups {
if p == sg.ID {
return nil
}
}
return fmt.Errorf("LoadBalancer does not have the security group")
}
}
开发者ID:hashicorp,项目名称:terraform,代码行数:23,代码来源:resource_openstack_lb_loadbalancer_v2_test.go
示例14: resourceLoadBalancerV2Read
func resourceLoadBalancerV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
lb, err := loadbalancers.Get(networkingClient, d.Id()).Extract()
if err != nil {
return CheckDeleted(d, err, "LoadBalancerV2")
}
log.Printf("[DEBUG] Retrieved OpenStack LBaaSV2 LoadBalancer %s: %+v", d.Id(), lb)
d.Set("name", lb.Name)
d.Set("description", lb.Description)
d.Set("vip_subnet_id", lb.VipSubnetID)
d.Set("tenant_id", lb.TenantID)
d.Set("vip_address", lb.VipAddress)
d.Set("vip_port_id", lb.VipPortID)
d.Set("admin_state_up", lb.AdminStateUp)
d.Set("flavor", lb.Flavor)
d.Set("provider", lb.Provider)
// Get any security groups on the VIP Port
if lb.VipPortID != "" {
port, err := ports.Get(networkingClient, lb.VipPortID).Extract()
if err != nil {
return err
}
d.Set("security_group_ids", port.SecurityGroups)
}
return nil
}
开发者ID:hashicorp,项目名称:terraform,代码行数:36,代码来源:resource_openstack_lb_loadbalancer_v2.go
示例15: WaitForRouterInterfaceToDetach
func WaitForRouterInterfaceToDetach(client *gophercloud.ServiceClient, routerInterfaceID string, secs int) error {
return gophercloud.WaitFor(secs, func() (bool, error) {
r, err := ports.Get(client, routerInterfaceID).Extract()
if err != nil {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return true, nil
}
if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok {
if errCode.Actual == 409 {
return false, nil
}
}
return false, err
}
if r.Status == "ACTIVE" {
return true, nil
}
return false, nil
})
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:24,代码来源:layer3.go
注:本文中的github.com/gophercloud/gophercloud/openstack/networking/v2/ports.Get函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论