本文整理汇总了Python中profitbricks.client.ProfitBricksService.create_loadbalancer方法的典型用法代码示例。如果您正苦于以下问题:Python ProfitBricksService.create_loadbalancer方法的具体用法?Python ProfitBricksService.create_loadbalancer怎么用?Python ProfitBricksService.create_loadbalancer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profitbricks.client.ProfitBricksService
的用法示例。
在下文中一共展示了ProfitBricksService.create_loadbalancer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestLoadBalancer
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_loadbalancer [as 别名]
class TestLoadBalancer(unittest.TestCase):
def setUp(self):
self.loadbalancer = ProfitBricksService(username="username", password="password")
def test_get_all(self):
loadbalancers = self.loadbalancer.list_loadbalancers(datacenter_id=datacenter_id)
self.assertEqual(len(loadbalancers), 4)
self.assertEqual(loadbalancers["items"][0]["id"], loadbalancer_id)
self.assertEqual(loadbalancers["items"][0]["properties"]["name"], "My LB")
def test_get_loadbalancer(self):
loadbalancer = self.loadbalancer.get_loadbalancer(datacenter_id=datacenter_id, loadbalancer_id=loadbalancer_id)
self.assertEqual(loadbalancer["properties"]["name"], "My LB")
self.assertEqual(loadbalancer["properties"]["ip"], "10.2.2.3")
self.assertTrue(loadbalancer["properties"]["dhcp"])
def test_delete_loadbalancer(self):
loadbalancer = self.loadbalancer.delete_loadbalancer(
datacenter_id=datacenter_id, loadbalancer_id=loadbalancer_id
)
self.assertTrue(loadbalancer)
def test_update_loadbalancer(self):
loadbalancer = self.loadbalancer.update_loadbalancer(
datacenter_id=datacenter_id, loadbalancer_id=loadbalancer_id, ip="10.2.2.4"
)
self.assertEqual(loadbalancer["properties"]["name"], "My LB")
self.assertEqual(loadbalancer["properties"]["ip"], "10.2.2.4")
self.assertTrue(loadbalancer["properties"]["dhcp"])
def test_create_loadbalancer(self):
i = LoadBalancer(name="My LB")
response = self.loadbalancer.create_loadbalancer(datacenter_id=datacenter_id, loadbalancer=i)
self.assertEqual(response["properties"]["name"], "My LB")
self.assertEqual(response["properties"]["ip"], "10.2.2.3")
self.assertTrue(response["properties"]["dhcp"])
def test_create_with_balancednics(self):
balancednics = ["<NIC-ID-1>", "<NIC-ID-2>"]
i = LoadBalancer(name="My LB", balancednics=balancednics)
response = self.loadbalancer.create_loadbalancer(datacenter_id=datacenter_id, loadbalancer=i)
self.assertEqual(response["properties"]["name"], "My LB")
self.assertEqual(response["properties"]["ip"], "10.2.2.3")
self.assertTrue(response["properties"]["dhcp"])
def test_create_optional_value(self):
i = LoadBalancer(name="My LB", ip="10.2.2.3", dhcp=True)
response = self.loadbalancer.create_loadbalancer(datacenter_id=datacenter_id, loadbalancer=i)
self.assertEqual(response["properties"]["name"], "My LB")
self.assertEqual(response["properties"]["ip"], "10.2.2.3")
self.assertTrue(response["properties"]["dhcp"])
def test_get_loadbalancer_members(self):
members = self.loadbalancer.get_loadbalancer_members(
datacenter_id=datacenter_id, loadbalancer_id=loadbalancer_id
)
self.assertEqual(len(members), 4)
self.assertEqual(members["items"][0]["id"], "<NIC-ID>")
self.assertEqual(members["items"][0]["properties"]["name"], "nic1")
self.assertEqual(members["items"][0]["properties"]["mac"], "AB:21:23:09:78:C2")
def test_add_loadbalanced_nic(self):
nic = "<NIC-ID-1"
response = self.loadbalancer.add_loadbalanced_nics(
datacenter_id=datacenter_id, loadbalancer_id=loadbalancer_id, nic_id=nic
)
self.assertEqual(response["properties"]["name"], "nic1")
self.assertEqual(response["properties"]["mac"], "AB:21:23:09:78:C2")
self.assertTrue(response["properties"]["dhcp"])
def test_get_balanced_nic(self):
response = self.loadbalancer.get_loadbalanced_nic(
datacenter_id=datacenter_id, loadbalancer_id=loadbalancer_id, nic_id=nic_id
)
self.assertEqual(response["properties"]["name"], "nic1")
self.assertEqual(response["properties"]["mac"], "AB:21:23:09:78:C2")
self.assertTrue(response["properties"]["dhcp"])
def test_remove_balanced_nic(self):
loadbalancer = self.loadbalancer.remove_loadbalanced_nic(
datacenter_id=datacenter_id, loadbalancer_id=loadbalancer_id, nic_id=nic_id
)
self.assertTrue(loadbalancer)