本文整理匯總了Python中profitbricks.client.ProfitBricksService.get_firewall_rules方法的典型用法代碼示例。如果您正苦於以下問題:Python ProfitBricksService.get_firewall_rules方法的具體用法?Python ProfitBricksService.get_firewall_rules怎麽用?Python ProfitBricksService.get_firewall_rules使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類profitbricks.client.ProfitBricksService
的用法示例。
在下文中一共展示了ProfitBricksService.get_firewall_rules方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestFirewall
# 需要導入模塊: from profitbricks.client import ProfitBricksService [as 別名]
# 或者: from profitbricks.client.ProfitBricksService import get_firewall_rules [as 別名]
class TestFirewall(unittest.TestCase):
def setUp(self):
self.firewall = ProfitBricksService(username='username', password='password')
def test_get_all(self):
firewalls = self.firewall.get_firewall_rules(
datacenter_id=datacenter_id,
server_id=server_id,
nic_id=nic_id)
self.assertEqual(len(firewalls), 4)
self.assertEqual(firewalls['items'][0]['id'], firewall_rule_id)
self.assertEqual(firewalls['items'][0]['properties']['name'], 'Open SSH port')
self.assertEqual(firewalls['items'][0]['properties']['portRangeStart'], 22)
def test_get(self):
firewall = self.firewall.get_firewall_rule(
datacenter_id=datacenter_id,
server_id=server_id,
nic_id=nic_id,
firewall_rule_id=firewall_rule_id)
self.assertEqual(firewall['id'], firewall_rule_id)
self.assertEqual(firewall['properties']['name'], 'Open SSH port')
self.assertEqual(firewall['properties']['portRangeStart'], 22)
def test_delete(self):
firewall = self.firewall.delete_firewall_rule(
datacenter_id=datacenter_id,
server_id=server_id,
nic_id=nic_id,
firewall_rule_id=firewall_rule_id)
self.assertTrue(firewall)
def test_update(self):
firewall = self.firewall.update_firewall_rule(
datacenter_id=datacenter_id,
server_id=server_id,
nic_id=nic_id,
firewall_rule_id=firewall_rule_id,
source_mac='01:98:22:22:44:22',
target_ip='123.100.101.102')
self.assertEqual(firewall['id'], firewall_rule_id)
self.assertEqual(firewall['properties']['name'], 'Open SSH port')
self.assertEqual(firewall['properties']['portRangeStart'], 22)
self.assertEqual(
firewall['properties']['sourceMac'], '01:98:22:22:44:22')
self.assertEqual(
firewall['properties']['targetIp'], '123.100.101.102')
def test_create(self):
i = FirewallRule(
name='Open SSH port',
protocol='TCP'
)
response = self.firewall.create_firewall_rule(
datacenter_id=datacenter_id,
server_id=server_id,
nic_id=nic_id,
firewall_rule=i)
self.assertEqual(response['id'], firewall_rule_id)
self.assertEqual(response['properties']['name'], 'Open SSH port')
self.assertEqual(response['properties']['portRangeStart'], 22)
self.assertEqual(response['properties']['protocol'], 'TCP')
self.assertEqual(
response['properties']['sourceMac'], '01:23:45:67:89:00')
def test_create_optional_value(self):
i = FirewallRule(
name='Open SSH port',
protocol='TCP',
source_mac='01:23:45:67:89:00',
source_ip='12.2.11.22',
port_range_start=22,
port_range_end=1000
)
response = self.firewall.create_firewall_rule(
datacenter_id=datacenter_id,
server_id=server_id,
nic_id=nic_id,
firewall_rule=i)
self.assertEqual(response['id'], firewall_rule_id)
self.assertEqual(response['properties']['name'], 'Open SSH port')
self.assertEqual(response['properties']['portRangeStart'], 22)
self.assertEqual(response['properties']['protocol'], 'TCP')