def test_serialize_create_security_group_rule_request_to_json(self):
     create_sec_group_rule_obj = CreateSecurityGroupRule(
         ip_protocol="tcp", from_port=80, to_port=8080, cidr="0.0.0.0/0", group_id=1, parent_group_id=2
     )
     json_serialized_obj = create_sec_group_rule_obj.serialize("json")
     expected_json = (
         '{"security_group_rule":'
         ' {"from_port": 80,'
         ' "ip_protocol": "tcp",'
         ' "to_port": 8080,'
         ' "parent_group_id": 2,'
         ' "cidr": "0.0.0.0/0",'
         ' "group_id": 1}}'
     )
     self.assertEqual(json_serialized_obj, expected_json)
 def test_serialize_create_security_group_rule_request_to_json(self):
     create_sec_group_rule_obj = CreateSecurityGroupRule(ip_protocol="tcp",
                                                         from_port=80,
                                                         to_port=8080,
                                                         cidr="0.0.0.0/0",
                                                         group_id=1,
                                                         parent_group_id=2)
     json_serialized_obj = create_sec_group_rule_obj.serialize("json")
     expected_json = ('{"security_group_rule":'
                      ' {"from_port": 80,'
                      ' "ip_protocol": "tcp",'
                      ' "to_port": 8080,'
                      ' "parent_group_id": 2,'
                      ' "cidr": "0.0.0.0/0",'
                      ' "group_id": 1}}')
     self.assertEqual(json_serialized_obj, expected_json)
 def test_serialize_host_update_request_to_xml(self):
     create_sec_group_rule_obj = CreateSecurityGroupRule(
         ip_protocol="tcp", from_port=80, to_port=8080, cidr="0.0.0.0/0", group_id=1, parent_group_id=2
     )
     xml_serialized_obj = create_sec_group_rule_obj.serialize("xml")
     expected_xml = (
         "<?xml version='1.0' encoding='UTF-8'?>"
         "<security_group_rule>"
         "<from_port>80</from_port>"
         "<ip_protocol>tcp</ip_protocol>"
         "<to_port>8080</to_port>"
         "<parent_group_id>2</parent_group_id>"
         "<cidr>0.0.0.0/0</cidr>"
         "<group_id>1</group_id>"
         "</security_group_rule>"
     )
     self.assertEqual(xml_serialized_obj, expected_xml)
 def test_serialize_host_update_request_to_xml(self):
     create_sec_group_rule_obj = CreateSecurityGroupRule(ip_protocol="tcp",
                                                         from_port=80,
                                                         to_port=8080,
                                                         cidr="0.0.0.0/0",
                                                         group_id=1,
                                                         parent_group_id=2)
     xml_serialized_obj = create_sec_group_rule_obj.serialize("xml")
     expected_xml = ('<?xml version=\'1.0\' encoding=\'UTF-8\'?>'
                     '<security_group_rule>'
                     '<from_port>80</from_port>'
                     '<ip_protocol>tcp</ip_protocol>'
                     '<to_port>8080</to_port>'
                     '<parent_group_id>2</parent_group_id>'
                     '<cidr>0.0.0.0/0</cidr>'
                     '<group_id>1</group_id>'
                     '</security_group_rule>')
     self.assertEqual(xml_serialized_obj, expected_xml)
예제 #5
0
 def create_rule(self,
                 from_port,
                 ip_protocol,
                 to_port,
                 parent_group_id,
                 cidr,
                 group_id,
                 requestslib_kwargs=None):
     url = '{base_url}/os-security-group-rules'.format(base_url=self.url)
     create_sec_group_request = \
         CreateSecurityGroupRule(from_port, ip_protocol, to_port,
                                 parent_group_id, cidr, group_id)
     resp = self.request('POST',
                         url,
                         response_entity_type=SecurityGroupRule,
                         request_entity=create_sec_group_request,
                         requestslib_kwargs=requestslib_kwargs)
     return resp