Exemple #1
0
    def set_cidr(self, cidr):
        """
        Sets the CIDR for the subnet. It previously checks for the correct CIDR format.

        :param cidr: The new CIDR for the subnet.
        :type cidr: ``str``
        :return: * *True*: When the new CIDR was set successfully.
            * *False*: If the CIDR format was wrong.
        :rtype: ``bool``
        """
        if cidr is None:
            if self._cidr is not None:
                import emuvim.api.openstack.ip_handler as IP
                IP.free_cidr(self._cidr, self.subnet_id)
            self._cidr = None
            self.reset_issued_ip_addresses()
            self.start_end_dict = dict()
            return True
        if not Net.check_cidr_format(cidr):
            return False

        self.reset_issued_ip_addresses()
        self.start_end_dict = Net.calculate_start_and_end_dict(cidr)
        self._cidr = cidr
        return True
    def set_cidr(self, cidr):
        """
        Sets the CIDR for the subnet. It previously checks for the correct CIDR format.

        :param cidr: The new CIDR for the subnet.
        :type cidr: ``str``
        :return: * *True*: When the new CIDR was set successfully.
            * *False*: If the CIDR format was wrong.
        :rtype: ``bool``
        """
        if cidr is None:
            if self._cidr is not None:
                import emuvim.api.openstack.ip_handler as IP
                IP.free_cidr(self._cidr, self.subnet_id)
            self._cidr = None
            self.reset_issued_ip_addresses()
            self.start_end_dict = dict()
            return True
        if not Net.check_cidr_format(cidr):
            return False

        self.reset_issued_ip_addresses()
        self.start_end_dict = Net.calculate_start_and_end_dict(cidr)
        self._cidr = cidr
        return True
Exemple #3
0
    def update_subnet_cidr(self, old_stack, new_stack):
        """
        Updates the subnet IP addresses. If the new stack contains subnets from the old stack it will take those
        IP addresses. Otherwise it will create new IP addresses for the subnet.

        :param old_stack: The currently running stack
        :type old_stack: :class:`heat.resources.stack`
        :param new_stack: The new created stack
        :type new_stack: :class:`heat.resources.stack`
        """
        for old_subnet in old_stack.nets.values():
            IP.free_cidr(old_subnet.get_cidr(), old_subnet.subnet_id)

        for subnet in new_stack.nets.values():
            subnet.clear_cidr()
            for old_subnet in old_stack.nets.values():
                if subnet.subnet_name == old_subnet.subnet_name:
                    if IP.assign_cidr(old_subnet.get_cidr(), subnet.subnet_id):
                        subnet.set_cidr(old_subnet.get_cidr())

        for subnet in new_stack.nets.values():
            if IP.is_cidr_issued(subnet.get_cidr()):
                continue

            cird = IP.get_new_cidr(subnet.subnet_id)
            subnet.set_cidr(cird)
        return