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


Golang common.ServiceClient函數代碼示例

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


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

示例1: TestURLs

func TestURLs(t *testing.T) {
    th.SetupHTTP()
    defer th.TeardownHTTP()

    th.AssertEquals(t, th.Endpoint()+"v2.0/security-groups", rootURL(fake.ServiceClient()))
    th.AssertEquals(t, th.Endpoint()+"v2.0/security-groups/foo", resourceURL(fake.ServiceClient(), "foo"))
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:7,代碼來源:requests_test.go

示例2: TestRequiredCreateOpts

func TestRequiredCreateOpts(t *testing.T) {
    res := Create(fake.ServiceClient(), CreateOpts{})
    if res.Err == nil {
        t.Fatalf("Expected error, got none")
    }

    res = Create(fake.ServiceClient(), CreateOpts{NetworkID: "foo"})
    if res.Err == nil {
        t.Fatalf("Expected error, got none")
    }

    res = Create(fake.ServiceClient(), CreateOpts{NetworkID: "foo", CIDR: "bar", IPVersion: 40})
    if res.Err == nil {
        t.Fatalf("Expected error, got none")
    }
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:16,代碼來源:requests_test.go

示例3: TestCreateWithOptionalFields

func TestCreateWithOptionalFields(t *testing.T) {
    th.SetupHTTP()
    defer th.TeardownHTTP()

    th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) {
        th.TestMethod(t, r, "POST")
        th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
        th.TestHeader(t, r, "Content-Type", "application/json")
        th.TestHeader(t, r, "Accept", "application/json")
        th.TestJSONRequest(t, r, `
{
    "network": {
            "name": "sample_network",
            "admin_state_up": true,
            "shared": true,
            "tenant_id": "12345"
    }
}
        `)

        w.WriteHeader(http.StatusCreated)
    })

    iTrue := true
    options := CreateOpts{Name: "sample_network", AdminStateUp: &iTrue, Shared: &iTrue, TenantID: "12345"}
    _, err := Create(fake.ServiceClient(), options).Extract()
    th.AssertNoErr(t, err)
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:28,代碼來源:requests_test.go

示例4: TestUpdate

func TestUpdate(t *testing.T) {
    th.SetupHTTP()
    defer th.TeardownHTTP()

    th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) {
        th.TestMethod(t, r, "PUT")
        th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
        th.TestHeader(t, r, "Content-Type", "application/json")
        th.TestHeader(t, r, "Accept", "application/json")
        th.TestJSONRequest(t, r, `
{
    "subnet": {
        "name": "my_new_subnet",
                "dns_nameservers": ["foo"],
                "host_routes": [{"destination":"","nexthop": "bar"}]
    }
}
        `)

        w.Header().Add("Content-Type", "application/json")
        w.WriteHeader(http.StatusCreated)

        fmt.Fprintf(w, `
{
    "subnet": {
        "name": "my_new_subnet",
        "enable_dhcp": true,
        "network_id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
        "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
        "dns_nameservers": [],
        "allocation_pools": [
            {
                "start": "10.0.0.2",
                "end": "10.0.0.254"
            }
        ],
        "host_routes": [],
        "ip_version": 4,
        "gateway_ip": "10.0.0.1",
        "cidr": "10.0.0.0/24",
        "id": "08eae331-0402-425a-923c-34f7cfe39c1b"
    }
}
    `)
    })

    opts := UpdateOpts{
        Name:           "my_new_subnet",
        DNSNameservers: []string{"foo"},
        HostRoutes: []HostRoute{
            HostRoute{NextHop: "bar"},
        },
    }
    s, err := Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract()
    th.AssertNoErr(t, err)

    th.AssertEquals(t, s.Name, "my_new_subnet")
    th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b")
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:59,代碼來源:requests_test.go

示例5: TestGet

func TestGet(t *testing.T) {
    th.SetupHTTP()
    defer th.TeardownHTTP()

    th.Mux.HandleFunc("/v2.0/security-groups/85cc3048-abc3-43cc-89b3-377341426ac5", 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, `
    {
      "security_group": {
        "description": "default",
        "id": "85cc3048-abc3-43cc-89b3-377341426ac5",
        "name": "default",
        "security_group_rules": [
        {
          "direction": "egress",
          "ethertype": "IPv6",
          "id": "3c0e45ff-adaf-4124-b083-bf390e5482ff",
          "port_range_max": null,
          "port_range_min": null,
          "protocol": null,
          "remote_group_id": null,
          "remote_ip_prefix": null,
          "security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5",
          "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
          },
        {
          "direction": "egress",
          "ethertype": "IPv4",
          "id": "93aa42e5-80db-4581-9391-3a608bd0e448",
          "port_range_max": null,
          "port_range_min": null,
          "protocol": null,
          "remote_group_id": null,
          "remote_ip_prefix": null,
          "security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5",
          "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
        }
        ],
        "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
      }
    }
  `)
    })

    sg, err := Get(fake.ServiceClient(), "85cc3048-abc3-43cc-89b3-377341426ac5").Extract()
    th.AssertNoErr(t, err)

    th.AssertEquals(t, "default", sg.Description)
    th.AssertEquals(t, "85cc3048-abc3-43cc-89b3-377341426ac5", sg.ID)
    th.AssertEquals(t, "default", sg.Name)
    th.AssertEquals(t, 2, len(sg.Rules))
    th.AssertEquals(t, "e4f50856753b4dc6afee5fa6b9b6c550", sg.TenantID)
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:58,代碼來源:delegate_test.go

示例6: TestRequiredCreateOpts

func TestRequiredCreateOpts(t *testing.T) {
    res := Create(fake.ServiceClient(), osRules.CreateOpts{Direction: "something"})
    if res.Err == nil {
        t.Fatalf("Expected error, got none")
    }
    res = Create(fake.ServiceClient(), osRules.CreateOpts{Direction: osRules.DirIngress, EtherType: "something"})
    if res.Err == nil {
        t.Fatalf("Expected error, got none")
    }
    res = Create(fake.ServiceClient(), osRules.CreateOpts{Direction: osRules.DirIngress, EtherType: osRules.Ether4})
    if res.Err == nil {
        t.Fatalf("Expected error, got none")
    }
    res = Create(fake.ServiceClient(), osRules.CreateOpts{Direction: osRules.DirIngress, EtherType: osRules.Ether4, SecGroupID: "something", Protocol: "foo"})
    if res.Err == nil {
        t.Fatalf("Expected error, got none")
    }
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:18,代碼來源:delegate_test.go

示例7: TestCreate

func TestCreate(t *testing.T) {
    th.SetupHTTP()
    defer th.TeardownHTTP()

    th.Mux.HandleFunc("/v2.0/security-group-rules", func(w http.ResponseWriter, r *http.Request) {
        th.TestMethod(t, r, "POST")
        th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
        th.TestHeader(t, r, "Content-Type", "application/json")
        th.TestHeader(t, r, "Accept", "application/json")
        th.TestJSONRequest(t, r, `
                    {
                      "security_group_rule": {
                        "direction": "ingress",
                        "port_range_min": 80,
                        "ethertype": "IPv4",
                        "port_range_max": 80,
                        "protocol": "tcp",
                        "remote_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5",
                        "security_group_id": "a7734e61-b545-452d-a3cd-0189cbd9747a"
                      }
                    }
                    `)

        w.Header().Add("Content-Type", "application/json")
        w.WriteHeader(http.StatusCreated)

        fmt.Fprintf(w, `
                      {
                        "security_group_rule": {
                          "direction": "ingress",
                          "ethertype": "IPv4",
                          "id": "2bc0accf-312e-429a-956e-e4407625eb62",
                          "port_range_max": 80,
                          "port_range_min": 80,
                          "protocol": "tcp",
                          "remote_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5",
                          "remote_ip_prefix": null,
                          "security_group_id": "a7734e61-b545-452d-a3cd-0189cbd9747a",
                          "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
                        }
                      }
                      `)
    })

    opts := osRules.CreateOpts{
        Direction:     "ingress",
        PortRangeMin:  80,
        EtherType:     "IPv4",
        PortRangeMax:  80,
        Protocol:      "tcp",
        RemoteGroupID: "85cc3048-abc3-43cc-89b3-377341426ac5",
        SecGroupID:    "a7734e61-b545-452d-a3cd-0189cbd9747a",
    }
    _, err := Create(fake.ServiceClient(), opts).Extract()
    th.AssertNoErr(t, err)
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:56,代碼來源:delegate_test.go

示例8: TestGet

func TestGet(t *testing.T) {
    th.SetupHTTP()
    defer th.TeardownHTTP()

    th.Mux.HandleFunc("/v2.0/subnets/54d6f61d-db07-451c-9ab3-b9609b6b6f0b", 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, `
{
    "subnet": {
        "name": "my_subnet",
        "enable_dhcp": true,
        "network_id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
        "tenant_id": "4fd44f30292945e481c7b8a0c8908869",
        "dns_nameservers": [],
        "allocation_pools": [
            {
                "start": "192.0.0.2",
                "end": "192.255.255.254"
            }
        ],
        "host_routes": [],
        "ip_version": 4,
        "gateway_ip": "192.0.0.1",
        "cidr": "192.0.0.0/8",
        "id": "54d6f61d-db07-451c-9ab3-b9609b6b6f0b"
    }
}
            `)
    })

    s, err := Get(fake.ServiceClient(), "54d6f61d-db07-451c-9ab3-b9609b6b6f0b").Extract()
    th.AssertNoErr(t, err)

    th.AssertEquals(t, s.Name, "my_subnet")
    th.AssertEquals(t, s.EnableDHCP, true)
    th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
    th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869")
    th.AssertDeepEquals(t, s.DNSNameservers, []string{})
    th.AssertDeepEquals(t, s.AllocationPools, []AllocationPool{
        AllocationPool{
            Start: "192.0.0.2",
            End:   "192.255.255.254",
        },
    })
    th.AssertDeepEquals(t, s.HostRoutes, []HostRoute{})
    th.AssertEquals(t, s.IPVersion, 4)
    th.AssertEquals(t, s.GatewayIP, "192.0.0.1")
    th.AssertEquals(t, s.CIDR, "192.0.0.0/8")
    th.AssertEquals(t, s.ID, "54d6f61d-db07-451c-9ab3-b9609b6b6f0b")
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:55,代碼來源:requests_test.go

示例9: TestList

func TestList(t *testing.T) {
    th.SetupHTTP()
    defer th.TeardownHTTP()

    th.Mux.HandleFunc("/v2.0/security-groups", 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, `
        {
          "security_groups": [
          {
            "description": "default",
            "id": "85cc3048-abc3-43cc-89b3-377341426ac5",
            "name": "default",
            "security_group_rules": [],
            "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
          }
          ]
        }
        `)
    })

    count := 0

    List(fake.ServiceClient(), osGroups.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
        count++
        actual, err := osGroups.ExtractGroups(page)
        if err != nil {
            t.Errorf("Failed to extract secgroups: %v", err)
            return false, err
        }

        expected := []osGroups.SecGroup{
            osGroups.SecGroup{
                Description: "default",
                ID:          "85cc3048-abc3-43cc-89b3-377341426ac5",
                Name:        "default",
                Rules:       []osRules.SecGroupRule{},
                TenantID:    "e4f50856753b4dc6afee5fa6b9b6c550",
            },
        }

        th.CheckDeepEquals(t, expected, actual)

        return true, nil
    })

    if count != 1 {
        t.Errorf("Expected 1 page, got %d", count)
    }
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:55,代碼來源:delegate_test.go

示例10: TestDelete

func TestDelete(t *testing.T) {
    th.SetupHTTP()
    defer th.TeardownHTTP()

    th.Mux.HandleFunc("/v2.0/ports/65c0ee9f-d634-4522-8954-51021b570b0d", func(w http.ResponseWriter, r *http.Request) {
        th.TestMethod(t, r, "DELETE")
        th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
        w.WriteHeader(http.StatusNoContent)
    })

    res := Delete(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d")
    th.AssertNoErr(t, res.Err)
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:13,代碼來源:requests_test.go

示例11: TestCreate

func TestCreate(t *testing.T) {
    th.SetupHTTP()
    defer th.TeardownHTTP()

    th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) {
        th.TestMethod(t, r, "POST")
        th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
        th.TestHeader(t, r, "Content-Type", "application/json")
        th.TestHeader(t, r, "Accept", "application/json")
        th.TestJSONRequest(t, r, `
{
    "network": {
        "name": "sample_network",
        "admin_state_up": true
    }
}
            `)

        w.Header().Add("Content-Type", "application/json")
        w.WriteHeader(http.StatusCreated)

        fmt.Fprintf(w, `
{
    "network": {
        "status": "ACTIVE",
        "subnets": [],
        "name": "net1",
        "admin_state_up": true,
        "tenant_id": "9bacb3c5d39d41a79512987f338cf177",
        "shared": false,
        "id": "4e8e5957-649f-477b-9e5b-f1f75b21c03c"
    }
}
        `)
    })

    iTrue := true
    options := CreateOpts{Name: "sample_network", AdminStateUp: &iTrue}
    n, err := Create(fake.ServiceClient(), options).Extract()
    th.AssertNoErr(t, err)

    th.AssertEquals(t, n.Status, "ACTIVE")
    th.AssertDeepEquals(t, n.Subnets, []string{})
    th.AssertEquals(t, n.Name, "net1")
    th.AssertEquals(t, n.AdminStateUp, true)
    th.AssertEquals(t, n.TenantID, "9bacb3c5d39d41a79512987f338cf177")
    th.AssertEquals(t, n.Shared, false)
    th.AssertEquals(t, n.ID, "4e8e5957-649f-477b-9e5b-f1f75b21c03c")
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:49,代碼來源:requests_test.go

示例12: TestList

func TestList(t *testing.T) {
    th.SetupHTTP()
    defer th.TeardownHTTP()

    th.Mux.HandleFunc("/v2.0/ports", 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, `
{
    "ports": [
        {
            "status": "ACTIVE",
            "binding:host_id": "devstack",
            "name": "",
            "admin_state_up": true,
            "network_id": "70c1db1f-b701-45bd-96e0-a313ee3430b3",
            "tenant_id": "",
            "device_owner": "network:router_gateway",
            "mac_address": "fa:16:3e:58:42:ed",
            "fixed_ips": [
                {
                    "subnet_id": "008ba151-0b8c-4a67-98b5-0d2b87666062",
                    "ip_address": "172.24.4.2"
                }
            ],
            "id": "d80b1a3b-4fc1-49f3-952e-1e2ab7081d8b",
            "security_groups": [],
            "device_id": "9ae135f4-b6e0-4dad-9e91-3c223e385824"
        }
    ]
}
      `)
    })

    count := 0

    List(fake.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
        count++
        actual, err := ExtractPorts(page)
        if err != nil {
            t.Errorf("Failed to extract subnets: %v", err)
            return false, nil
        }

        expected := []Port{
            Port{
                Status:       "ACTIVE",
                Name:         "",
                AdminStateUp: true,
                NetworkID:    "70c1db1f-b701-45bd-96e0-a313ee3430b3",
                TenantID:     "",
                DeviceOwner:  "network:router_gateway",
                MACAddress:   "fa:16:3e:58:42:ed",
                FixedIPs: []IP{
                    IP{
                        SubnetID:  "008ba151-0b8c-4a67-98b5-0d2b87666062",
                        IPAddress: "172.24.4.2",
                    },
                },
                ID:             "d80b1a3b-4fc1-49f3-952e-1e2ab7081d8b",
                SecurityGroups: []string{},
                DeviceID:       "9ae135f4-b6e0-4dad-9e91-3c223e385824",
            },
        }

        th.CheckDeepEquals(t, expected, actual)

        return true, nil
    })

    if count != 1 {
        t.Errorf("Expected 1 page, got %d", count)
    }
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:78,代碼來源:requests_test.go


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