本文整理汇总了Golang中github.com/gophercloud/gophercloud/openstack/networking/v2/common.ServiceClient函数的典型用法代码示例。如果您正苦于以下问题:Golang ServiceClient函数的具体用法?Golang ServiceClient怎么用?Golang ServiceClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestRequiredPoolCreateOpts
func TestRequiredPoolCreateOpts(t *testing.T) {
res := pools.Create(fake.ServiceClient(), pools.CreateOpts{})
if res.Err == nil {
t.Fatalf("Expected error, got none")
}
res = pools.Create(fake.ServiceClient(), pools.CreateOpts{
LBMethod: pools.LBMethod("invalid"),
Protocol: pools.ProtocolHTTPS,
LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a",
})
if res.Err == nil {
t.Fatalf("Expected error, but got none")
}
res = pools.Create(fake.ServiceClient(), pools.CreateOpts{
LBMethod: pools.LBMethodRoundRobin,
Protocol: pools.Protocol("invalid"),
LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a",
})
if res.Err == nil {
t.Fatalf("Expected error, but got none")
}
res = pools.Create(fake.ServiceClient(), pools.CreateOpts{
LBMethod: pools.LBMethodRoundRobin,
Protocol: pools.ProtocolHTTPS,
})
if res.Err == nil {
t.Fatalf("Expected error, but got none")
}
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:31,代码来源:requests_test.go
示例2: TestRequiredCreateOpts
func TestRequiredCreateOpts(t *testing.T) {
res := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{})
if res.Err == nil {
t.Fatalf("Expected error, got none")
}
res = monitors.Create(fake.ServiceClient(), monitors.CreateOpts{Type: monitors.TypeHTTP})
if res.Err == nil {
t.Fatalf("Expected error, got none")
}
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:10,代码来源:requests_test.go
示例3: TestRequiredFieldsForCreate
func TestRequiredFieldsForCreate(t *testing.T) {
res1 := floatingips.Create(fake.ServiceClient(), floatingips.CreateOpts{FloatingNetworkID: ""})
if res1.Err == nil {
t.Fatalf("Expected error, got none")
}
res2 := floatingips.Create(fake.ServiceClient(), floatingips.CreateOpts{FloatingNetworkID: "foo", PortID: ""})
if res2.Err == nil {
t.Fatalf("Expected error, got none")
}
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:11,代码来源:requests_test.go
示例4: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleGet(t)
n, err := portsbinding.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.DeviceID, "5e3898d7-11be-483e-9732-b2f5eccd2b2e")
th.AssertEquals(t, n.HostID, "devstack")
th.AssertEquals(t, n.VNICType, "normal")
th.AssertEquals(t, n.VIFType, "ovs")
th.AssertDeepEquals(t, n.VIFDetails, map[string]interface{}{"port_filter": true, "ovs_hybrid_plug": true})
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:28,代码来源:requests_test.go
示例5: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/extensions/agent", 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, `
{
"extension": {
"updated": "2013-02-03T10:00:00-00:00",
"name": "agent",
"links": [],
"namespace": "http://docs.openstack.org/ext/agent/api/v2.0",
"alias": "agent",
"description": "The agent management extension."
}
}
`)
})
ext, err := extensions.Get(fake.ServiceClient(), "agent").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, ext.Updated, "2013-02-03T10:00:00-00:00")
th.AssertEquals(t, ext.Name, "agent")
th.AssertEquals(t, ext.Namespace, "http://docs.openstack.org/ext/agent/api/v2.0")
th.AssertEquals(t, ext.Alias, "agent")
th.AssertEquals(t, ext.Description, "The agent management extension.")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:34,代码来源:delegate_test.go
示例6: TestCreate
func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/fw/firewall_policies", 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, `
{
"firewall_policy":{
"name": "policy",
"firewall_rules": [
"98a58c87-76be-ae7c-a74e-b77fffb88d95",
"11a58c87-76be-ae7c-a74e-b77fffb88a32"
],
"description": "Firewall policy",
"tenant_id": "9145d91459d248b1b02fdaca97c6a75d",
"audited": true,
"shared": false
}
}
`)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `
{
"firewall_policy":{
"name": "policy",
"firewall_rules": [
"98a58c87-76be-ae7c-a74e-b77fffb88d95",
"11a58c87-76be-ae7c-a74e-b77fffb88a32"
],
"tenant_id": "9145d91459d248b1b02fdaca97c6a75d",
"audited": false,
"id": "f2b08c1e-aa81-4668-8ae1-1401bcb0576c",
"description": "Firewall policy"
}
}
`)
})
options := policies.CreateOpts{
TenantID: "9145d91459d248b1b02fdaca97c6a75d",
Name: "policy",
Description: "Firewall policy",
Shared: gophercloud.Disabled,
Audited: gophercloud.Enabled,
Rules: []string{
"98a58c87-76be-ae7c-a74e-b77fffb88d95",
"11a58c87-76be-ae7c-a74e-b77fffb88a32",
},
}
_, err := policies.Create(fake.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:60,代码来源:requests_test.go
示例7: 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)
fmt.Fprintf(w, `{}`)
})
iTrue := true
options := networks.CreateOpts{Name: "sample_network", AdminStateUp: &iTrue, Shared: &iTrue, TenantID: "12345"}
_, err := networks.Create(fake.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:requests_test.go
示例8: TestListPools
func TestListPools(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandlePoolListSuccessfully(t)
pages := 0
err := pools.List(fake.ServiceClient(), pools.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
pages++
actual, err := pools.ExtractPools(page)
if err != nil {
return false, err
}
if len(actual) != 2 {
t.Fatalf("Expected 2 pools, got %d", len(actual))
}
th.CheckDeepEquals(t, PoolWeb, actual[0])
th.CheckDeepEquals(t, PoolDb, actual[1])
return true, nil
})
th.AssertNoErr(t, err)
if pages != 1 {
t.Errorf("Expected 1 page, saw %d", pages)
}
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:requests_test.go
示例9: TestRequiredCreateOpts
func TestRequiredCreateOpts(t *testing.T) {
res := subnets.Create(fake.ServiceClient(), subnets.CreateOpts{})
if res.Err == nil {
t.Fatalf("Expected error, got none")
}
res = subnets.Create(fake.ServiceClient(), subnets.CreateOpts{NetworkID: "foo"})
if res.Err == nil {
t.Fatalf("Expected error, got none")
}
res = subnets.Create(fake.ServiceClient(), subnets.CreateOpts{NetworkID: "foo", CIDR: "bar", IPVersion: 40})
if res.Err == nil {
t.Fatalf("Expected error, got none")
}
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:16,代码来源:requests_test.go
示例10: TestCreateAnyProtocol
func TestCreateAnyProtocol(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/fw/firewall_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, `
{
"firewall_rule": {
"protocol": null,
"description": "any to 192.168.1.0/24",
"destination_ip_address": "192.168.1.0/24",
"name": "any_to_192.168.1.0/24",
"action": "allow",
"tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61"
}
}
`)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `
{
"firewall_rule":{
"protocol": null,
"description": "any to 192.168.1.0/24",
"source_port": null,
"source_ip_address": null,
"destination_ip_address": "192.168.1.0/24",
"firewall_policy_id": "e2a5fb51-698c-4898-87e8-f1eee6b50919",
"position": 2,
"destination_port": null,
"id": "f03bd950-6c56-4f5e-a307-45967078f507",
"name": "any_to_192.168.1.0/24",
"tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61",
"enabled": true,
"action": "allow",
"ip_version": 4,
"shared": false
}
}
`)
})
options := rules.CreateOpts{
TenantID: "80cf934d6ffb4ef5b244f1c512ad1e61",
Protocol: rules.ProtocolAny,
Description: "any to 192.168.1.0/24",
DestinationIPAddress: "192.168.1.0/24",
Name: "any_to_192.168.1.0/24",
Action: "allow",
}
_, err := rules.Create(fake.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:60,代码来源:requests_test.go
示例11: TestListMembers
func TestListMembers(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleMemberListSuccessfully(t)
pages := 0
err := pools.ListMembers(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.ListMembersOpts{}).EachPage(func(page pagination.Page) (bool, error) {
pages++
actual, err := pools.ExtractMembers(page)
if err != nil {
return false, err
}
if len(actual) != 2 {
t.Fatalf("Expected 2 members, got %d", len(actual))
}
th.CheckDeepEquals(t, MemberWeb, actual[0])
th.CheckDeepEquals(t, MemberDb, actual[1])
return true, nil
})
th.AssertNoErr(t, err)
if pages != 1 {
t.Errorf("Expected 1 page, saw %d", pages)
}
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:requests_test.go
示例12: TestUpdate
func TestUpdate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleUpdate(t)
options := portsbinding.UpdateOpts{
UpdateOptsBuilder: ports.UpdateOpts{
Name: "new_port_name",
FixedIPs: []ports.IP{
{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"},
},
SecurityGroups: []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"},
},
HostID: "HOST1",
VNICType: "normal",
}
s, err := portsbinding.Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", options).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.Name, "new_port_name")
th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{
{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"},
})
th.AssertDeepEquals(t, s.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"})
th.AssertEquals(t, s.HostID, "HOST1")
th.AssertEquals(t, s.VNICType, "normal")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:requests_test.go
示例13: TestAssociateHealthMonitor
func TestAssociateHealthMonitor(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/lb/pools/332abe93-f488-41ba-870b-2ac66be7f853/health_monitors", 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, `
{
"health_monitor":{
"id":"b624decf-d5d3-4c66-9a3d-f047e7786181"
}
}
`)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `{}`)
})
_, err := pools.AssociateMonitor(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "b624decf-d5d3-4c66-9a3d-f047e7786181").Extract()
th.AssertNoErr(t, err)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:25,代码来源:requests_test.go
示例14: 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 := subnets.UpdateOpts{
Name: "my_new_subnet",
DNSNameservers: []string{"foo"},
HostRoutes: []subnets.HostRoute{
{NextHop: "bar"},
},
}
s, err := subnets.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:jrperritt,项目名称:gophercloud-1,代码行数:59,代码来源:requests_test.go
示例15: TestUpdate
func TestUpdate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/lb/health_monitors/b05e44b5-81f9-4551-b474-711a722698f7", 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, `
{
"health_monitor":{
"delay": 30,
"timeout": 20,
"max_retries": 10,
"url_path": "/another_check",
"expected_codes": "301",
"admin_state_up": true
}
}
`)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusAccepted)
fmt.Fprintf(w, `
{
"health_monitor": {
"admin_state_up": true,
"tenant_id": "4fd44f30292945e481c7b8a0c8908869",
"delay": 30,
"max_retries": 10,
"http_method": "GET",
"timeout": 20,
"pools": [
{
"status": "PENDING_CREATE",
"status_description": null,
"pool_id": "6e55751f-6ad4-4e53-b8d4-02e442cd21df"
}
],
"type": "PING",
"id": "b05e44b5-81f9-4551-b474-711a722698f7"
}
}
`)
})
_, err := monitors.Update(fake.ServiceClient(), "b05e44b5-81f9-4551-b474-711a722698f7", monitors.UpdateOpts{
Delay: 30,
Timeout: 20,
MaxRetries: 10,
URLPath: "/another_check",
ExpectedCodes: "301",
AdminStateUp: gophercloud.Enabled,
}).Extract()
th.AssertNoErr(t, err)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:59,代码来源:requests_test.go
示例16: TestDeleteListener
func TestDeleteListener(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleListenerDeletionSuccessfully(t)
res := listeners.Delete(fake.ServiceClient(), "4ec89087-d057-4e2c-911f-60a3b47ee304")
th.AssertNoErr(t, res.Err)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:8,代码来源:requests_test.go
示例17: TestDeletePool
func TestDeletePool(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandlePoolDeletionSuccessfully(t)
res := pools.Delete(fake.ServiceClient(), "c3741b06-df4d-4715-b142-276b6bce75ab")
th.AssertNoErr(t, res.Err)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:8,代码来源:requests_test.go
示例18: TestDeleteMember
func TestDeleteMember(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleMemberDeletionSuccessfully(t)
res := pools.DeleteMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "2a280670-c202-4b0b-a562-34077415aabf")
th.AssertNoErr(t, res.Err)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:8,代码来源:requests_test.go
示例19: TestDeleteHealthmonitor
func TestDeleteHealthmonitor(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleHealthmonitorDeletionSuccessfully(t)
res := monitors.Delete(fake.ServiceClient(), "5d4b5228-33b0-4e60-b225-9b727c1a20e7")
th.AssertNoErr(t, res.Err)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:8,代码来源:requests_test.go
示例20: TestDeleteLoadbalancer
func TestDeleteLoadbalancer(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleLoadbalancerDeletionSuccessfully(t)
res := loadbalancers.Delete(fake.ServiceClient(), "36e08a3e-a78f-4b40-a229-1e7e23eee1ab")
th.AssertNoErr(t, res.Err)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:8,代码来源:requests_test.go
注:本文中的github.com/gophercloud/gophercloud/openstack/networking/v2/common.ServiceClient函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论