示例#1
0
 def get_firewall_rule(self, server_uuid, firewall_rule_position):
     """
     Return a FirewallRule object based on server uuid and rule position.
     """
     url = '/server/{0}/firewall_rule/{1}'.format(server_uuid, firewall_rule_position)
     res = self.get_request(url)
     return FirewallRule(**res['firewall_rule'])
示例#2
0
    def test_add_firewall_rule(self, manager):
        Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
        server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')

        responses.add_callback(
            responses.POST,
            Mock.base_url +
            '/server/00798b85-efdc-41ca-8021-f6ef457b8531/firewall_rule',
            content_type='application/json',
            callback=firewall_rule_callback)

        returned_firewall = server.add_firewall_rule(
            FirewallRule(position='1',
                         direction='in',
                         family='IPv4',
                         protocol='tcp',
                         source_address_start='192.168.1.1',
                         source_address_end='192.168.1.255',
                         destination_port_start='22',
                         destination_port_end='22',
                         action='accept'))

        # everything should run without errors, returned created object
        assert returned_firewall.position == '1'
        assert returned_firewall.direction == 'in'
        assert returned_firewall.source_address_end == '192.168.1.255'
示例#3
0
    def create_firewall_rule(self, server_uuid, firewall_rule_body):
        """
        Create a new firewall rule for a given server uuid.

        The rule can begiven as a dict or with FirewallRule.prepare_post_body().
        Returns a FirewallRule object.
        """
        url = '/server/{0}/firewall_rule'.format(server_uuid)

        body = {'firewall_rule': firewall_rule_body}
        res = self.post_request(url, body)
        return FirewallRule(**res['firewall_rule'])
示例#4
0
    def get_firewall_rules(self, server_uuid):
        """
        Return all FirewallRule objects based on a server uuid.
        """
        url = '/server/{0}/firewall_rule'.format(server_uuid)

        res = self.get_request(url)

        firewall_rules = []
        for firewall_rule in res['firewall_rules']['firewall_rule']:
            firewall_rules.append(FirewallRule(**firewall_rule))

        return firewall_rules
    def get_firewall_rules(self, server):
        """
        Return all FirewallRule objects based on a server instance or uuid.
        """
        server_uuid, server_instance = uuid_and_instance(server)

        url = '/server/{0}/firewall_rule'.format(server_uuid)
        res = self.get_request(url)

        return [
            FirewallRule(server=server_instance, **firewall_rule)
            for firewall_rule in res['firewall_rules']['firewall_rule']
        ]
示例#6
0
        password_delivery='none',
        storage_devices=[
            Storage(os='Debian 10.0', size=30)
        ],
        login_user=login_user_block('testuser', ['ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x [email protected]'], True),
        )
}


FIREWALL_RULES = [
    FirewallRule(
        position='1',
        direction='in',
        family='IPv4',
        protocol='tcp',
        source_address_start='192.168.1.1',
        source_address_end='192.168.1.255',
        destination_port_start='22',
        destination_port_end='22',
        action='accept'
    ),
    FirewallRule(
        position='2',
        direction='in',
        family='IPv4',
        protocol='tcp',
        source_address_start='192.168.1.1',
        source_address_end='192.168.1.255',
        destination_port_start='21',
        destination_port_end='21',
        action='accept'
示例#7
0
 def get_firewall_rules(self):
     data = self.read_json_data("firewall")
     return [
         FirewallRule(**firewall_rule)
         for firewall_rule in data["firewall_rules"]["firewall_rule"]
     ]