本文整理汇总了Python中profitbricks.client.ProfitBricksService.create_lan方法的典型用法代码示例。如果您正苦于以下问题:Python ProfitBricksService.create_lan方法的具体用法?Python ProfitBricksService.create_lan怎么用?Python ProfitBricksService.create_lan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profitbricks.client.ProfitBricksService
的用法示例。
在下文中一共展示了ProfitBricksService.create_lan方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestLan
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_lan [as 别名]
class TestLan(unittest.TestCase):
@classmethod
def setUpClass(self):
self.resource = resource()
self.client = ProfitBricksService(
username=configuration.USERNAME,
password=configuration.PASSWORD,
headers=configuration.HEADERS)
# Create test datacenter.
self.datacenter = self.client.create_datacenter(
datacenter=Datacenter(**self.resource['datacenter']))
wait_for_completion(self.client, self.datacenter, 'create_datacenter')
# Create test LAN.
self.lan = self.client.create_lan(
datacenter_id=self.datacenter['id'],
lan=LAN(**self.resource['lan']))
wait_for_completion(self.client, self.lan, 'create_lan')
# Create test server.
self.server = self.client.create_server(
datacenter_id=self.datacenter['id'],
server=Server(**self.resource['server']))
wait_for_completion(self.client, self.server, 'create_server')
# Create test NIC1.
nic1 = NIC(**self.resource['nic'])
nic1.lan = self.lan['id']
self.nic1 = self.client.create_nic(
datacenter_id=self.datacenter['id'],
server_id=self.server['id'],
nic=nic1)
wait_for_completion(self.client, self.nic1, 'create_nic1')
# Create test NIC2.
nic2 = NIC(**self.resource['nic'])
nic2.lan = self.lan['id']
self.nic2 = self.client.create_nic(
datacenter_id=self.datacenter['id'],
server_id=self.server['id'],
nic=nic2)
wait_for_completion(self.client, self.nic2, 'create_nic2')
@classmethod
def tearDownClass(self):
self.client.delete_datacenter(datacenter_id=self.datacenter['id'])
示例2: ProfitBricksService
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_lan [as 别名]
from profitbricks.client import ProfitBricksService, LAN
lan_id = '4'
datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
client = ProfitBricksService(
username='username', password='password')
nics = ['<NIC-ID-1>', '<NIC-ID-2>']
i = LAN(
name='public Lan 4',
public=True,
nics=nics)
response = client.create_lan(datacenter_id=datacenter_id, lan=i)
"""Create LAN
"""
from profitbricks.client import ProfitBricksService, LAN
lan_id = '4'
datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
client = ProfitBricksService(
username='username', password='password')
i = LAN(
name='public Lan 4',
public=True)
示例3: TestLan
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_lan [as 别名]
class TestLan(unittest.TestCase):
def setUp(self):
self.lan = ProfitBricksService(username='username', password='password')
def test_list_lans(self):
lans = self.lan.list_lans(datacenter_id=datacenter_id)
self.assertEqual(len(lans), 4)
self.assertEqual(lans['items'][0]['id'], lan_id)
self.assertEqual(lans['items'][0]['properties']['name'], 'public Lan 4')
def test_get_lan(self):
lan = self.lan.get_lan(datacenter_id=datacenter_id, lan_id=lan_id)
self.assertEqual(lan['properties']['name'], 'public Lan 4')
self.assertTrue(lan['properties']['public'])
def test_delete_lan(self):
lan = self.lan.delete_lan(datacenter_id=datacenter_id, lan_id=lan_id)
self.assertTrue(lan)
def test_update_lan(self):
lan = self.lan.update_lan(datacenter_id=datacenter_id,
lan_id=lan_id,
name='new lan 4 name',
public=False)
self.assertEqual(lan['properties']['name'], 'public Lan 4')
self.assertTrue(lan['properties']['public'])
def test_create_lan(self):
i = LAN(
name='public Lan 4',
public=True)
response = self.lan.create_lan(datacenter_id=datacenter_id, lan=i)
self.assertEqual(response['properties']['name'], 'public Lan 4')
self.assertTrue(response['properties']['public'])
def test_create_complex_lan(self):
nics = ['<NIC-ID-1>', '<NIC-ID-2>']
i = LAN(
name='public Lan 4',
public=True,
nics=nics)
response = self.lan.create_lan(datacenter_id=datacenter_id, lan=i)
self.assertEqual(response['properties']['name'], 'public Lan 4')
self.assertTrue(response['properties']['public'])
def test_get_lan_members(self):
members = self.lan.get_lan_members(datacenter_id=datacenter_id,
lan_id=lan_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')
示例4: TestLan
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_lan [as 别名]
class TestLan(unittest.TestCase):
@classmethod
def setUpClass(self):
self.resource = resource()
self.client = ProfitBricksService(
username=configuration.USERNAME,
password=configuration.PASSWORD,
headers=configuration.HEADERS)
# Create test datacenter.
self.datacenter = self.client.create_datacenter(
datacenter=Datacenter(**self.resource['datacenter']))
wait_for_completion(self.client, self.datacenter, 'create_datacenter')
# Create test LAN.
self.lan = self.client.create_lan(
datacenter_id=self.datacenter['id'],
lan=LAN(**self.resource['lan']))
wait_for_completion(self.client, self.lan, 'create_lan')
# Create test server.
self.server = self.client.create_server(
datacenter_id=self.datacenter['id'],
server=Server(**self.resource['server']))
wait_for_completion(self.client, self.server, 'create_server')
# Create test NIC1.
nic1 = NIC(**self.resource['nic'])
nic1.lan = self.lan['id']
self.nic1 = self.client.create_nic(
datacenter_id=self.datacenter['id'],
server_id=self.server['id'],
nic=nic1)
wait_for_completion(self.client, self.nic1, 'create_nic1')
# Create test NIC2.
nic2 = NIC(**self.resource['nic'])
nic2.lan = self.lan['id']
self.nic2 = self.client.create_nic(
datacenter_id=self.datacenter['id'],
server_id=self.server['id'],
nic=nic2)
wait_for_completion(self.client, self.nic2, 'create_nic2')
@classmethod
def tearDownClass(self):
self.client.delete_datacenter(datacenter_id=self.datacenter['id'])
def test_list_lans(self):
lans = self.client.list_lans(datacenter_id=self.datacenter['id'])
self.assertGreater(len(lans), 0)
self.assertEqual(lans['items'][0]['type'], 'lan')
self.assertIn(lans['items'][0]['id'], ('1', '2', '3'))
self.assertEqual(lans['items'][0]['properties']['name'], self.resource['lan']['name'])
self.assertTrue(lans['items'][0]['properties']['public'], self.resource['lan']['public'])
def test_get_lan(self):
lan = self.client.get_lan(datacenter_id=self.datacenter['id'], lan_id=self.lan['id'])
self.assertEqual(lan['type'], 'lan')
self.assertEqual(lan['id'], self.lan['id'])
self.assertEqual(lan['properties']['name'], self.resource['lan']['name'])
self.assertTrue(lan['properties']['public'], self.resource['lan']['public'])
def test_delete_lan(self):
lan = self.client.create_lan(
datacenter_id=self.datacenter['id'],
lan=LAN(**self.resource['lan']))
wait_for_completion(self.client, self.lan, 'create_lan')
lan = self.client.delete_lan(datacenter_id=self.datacenter['id'], lan_id=lan['id'])
self.assertTrue(lan)
def test_update_lan(self):
lan = self.client.update_lan(
datacenter_id=self.datacenter['id'],
lan_id=self.lan['id'],
name=self.resource['lan']['name'] + ' RENAME',
public=False)
self.assertEqual(lan['type'], 'lan')
self.assertEqual(lan['properties']['name'], self.resource['lan']['name'] + ' RENAME')
self.assertFalse(lan['properties']['public'])
def test_create_lan(self):
self.assertEqual(self.lan['id'], '1')
self.assertEqual(self.lan['type'], 'lan')
self.assertEqual(self.lan['properties']['name'], self.resource['lan']['name'])
self.assertEqual(self.lan['properties']['public'], self.resource['lan']['public'])
def test_create_complex_lan(self):
resource = NIC(**self.resource['nic'])
nic1 = self.client.create_nic(
datacenter_id=self.datacenter['id'],
server_id=self.server['id'],
nic=resource)
wait_for_completion(self.client, nic1, 'create_nic1')
#.........这里部分代码省略.........
示例5: main
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_lan [as 别名]
#.........这里部分代码省略.........
requests = []
print("create Servers {}".format(str(dc)))
# we do NOT consider dangling volumes, only server-attached ones
for server in dcdef["entities"]["servers"]["items"]:
print("- server {}".format(server["properties"]["name"]))
if "custom" in server and "id" in server["custom"]:
srv_id = server["custom"]["id"]
print("using existing server w/ id {}".format(str(srv_id)))
else:
dcsrv = getServerObject(server)
print("OBJ: {}".format(str(dcsrv)))
response = pbclient.create_server(dc_id, dcsrv)
server.update({"custom": {"id": response["id"]}})
requests.append(response["requestId"])
# end for(server)
if len(requests) != 0:
result = wait_for_requests(pbclient, requests, initial_wait=10, scaleup=15)
print("wait loop returned {}".format(str(result)))
tmpfile = usefile + ".tmp_postsrv"
write_dc_definition(pbclient, dcdef, tmpfile)
else:
print("all servers existed already")
# TODO: only do this if we have lan entities
requests = []
# Huuh, looks like we get unpredictable order for LANs!
# Nope, order of creation determines the LAN id,
# thus we better wait for each request
print("create LANs {}".format(str(dc)))
for lan in dcdef["entities"]["lans"]["items"]:
print("- lan {}".format(lan["properties"]["name"]))
dclan = getLANObject(lan)
print("OBJ: {}".format(str(dclan)))
response = pbclient.create_lan(dc_id, dclan)
lan.update({"custom": {"id": response["id"]}})
result = wait_for_request(pbclient, response["requestId"])
print("wait loop returned {}".format(str(result)))
# end for(lan)
tmpfile = usefile + ".tmp_postlan"
write_dc_definition(pbclient, dcdef, tmpfile)
requests = []
# Attention:
# NICs appear in OS in the order, they are created.
# But DCD rearranges the display by ascending MAC addresses.
# This does not change the OS order.
# MAC may not be available from create response,
# thus we wait for each request :-(
print("create NICs {}".format(str(dc)))
for server in dcdef["entities"]["servers"]["items"]:
print("- server {}".format(server["properties"]["name"]))
srv_id = server["custom"]["id"]
if "nics" not in server["entities"]:
print(" server {} has no NICs".format(server["properties"]["name"]))
continue
macmap = dict()
for nic in server["entities"]["nics"]["items"]:
dcnic = getNICObject(nic)
response = pbclient.create_nic(dc_id, srv_id, dcnic)
# print("dcnic response {}".format(str(response)))
# mac = response['properties']['mac'] # we don't get it here !?
nic_id = response["id"]
result = wait_for_request(pbclient, response["requestId"])
print("wait loop returned {}".format(str(result)))
response = pbclient.get_nic(dc_id, srv_id, nic_id, 2)
mac = response["properties"]["mac"]