예제 #1
0
파일: responses.py 프로젝트: bpandola/moto
    def list_or_create_hostzone_response(self, request, full_url, headers):
        self.setup_class(request, full_url, headers)

        if request.method == "POST":
            elements = xmltodict.parse(self.body)
            if "HostedZoneConfig" in elements["CreateHostedZoneRequest"]:
                comment = elements["CreateHostedZoneRequest"][
                    "HostedZoneConfig"]["Comment"]
                try:
                    # in boto3, this field is set directly in the xml
                    private_zone = elements["CreateHostedZoneRequest"][
                        "HostedZoneConfig"]["PrivateZone"]
                except KeyError:
                    # if a VPC subsection is only included in xmls params when private_zone=True,
                    # see boto: boto/route53/connection.py
                    private_zone = "VPC" in elements["CreateHostedZoneRequest"]
            else:
                comment = None
                private_zone = False

            name = elements["CreateHostedZoneRequest"]["Name"]

            if name[-1] != ".":
                name += "."

            new_zone = route53_backend.create_hosted_zone(
                name, comment=comment, private_zone=private_zone)
            template = Template(CREATE_HOSTED_ZONE_RESPONSE)
            return 201, headers, template.render(zone=new_zone)

        elif request.method == "GET":
            all_zones = route53_backend.list_hosted_zones()
            template = Template(LIST_HOSTED_ZONES_RESPONSE)
            return 200, headers, template.render(zones=all_zones)
예제 #2
0
    def list_or_create_hostzone_response(self, request, full_url, headers):
        self.setup_class(request, full_url, headers)

        # Set these here outside the scope of the try/except
        # so they're defined later when we call create_hosted_zone()
        vpcid = None
        vpcregion = None
        if request.method == "POST":
            elements = xmltodict.parse(self.body)
            zone_request = elements["CreateHostedZoneRequest"]
            if "HostedZoneConfig" in zone_request:
                zone_config = zone_request["HostedZoneConfig"]
                comment = zone_config["Comment"]
                if zone_request.get("VPC", {}).get("VPCId", None):
                    private_zone = True
                else:
                    private_zone = self._convert_to_bool(
                        zone_config.get("PrivateZone", False))
            else:
                comment = None
                private_zone = False

            # It is possible to create a Private Hosted Zone without
            # associating VPC at the time of creation.
            if self._convert_to_bool(private_zone):
                if zone_request.get("VPC", None) is not None:
                    vpcid = zone_request["VPC"].get("VPCId", None)
                    vpcregion = zone_request["VPC"].get("VPCRegion", None)

            name = zone_request["Name"]

            if name[-1] != ".":
                name += "."
            delegation_set_id = zone_request.get("DelegationSetId")

            new_zone = route53_backend.create_hosted_zone(
                name,
                comment=comment,
                private_zone=private_zone,
                vpcid=vpcid,
                vpcregion=vpcregion,
                delegation_set_id=delegation_set_id,
            )
            template = Template(CREATE_HOSTED_ZONE_RESPONSE)
            return 201, headers, template.render(zone=new_zone)

        elif request.method == "GET":
            all_zones = route53_backend.list_hosted_zones()
            template = Template(LIST_HOSTED_ZONES_RESPONSE)
            return 200, headers, template.render(zones=all_zones)