Example #1
0
    def revert(self, *args, **kwargs):
        """Revert CreateVmGroup Task

        This method is executed upon failure of the CreateVmGroup Task or the
        Flow that the Task is part of.

        :param args: positional arguments that the task required to execute.
        :type args: list
        :param kwargs: keyword arguments that the task required to execute; the
                       special key `result` will contain the :meth:`execute`
                       results (if any) and the special key `flow_failures`
                       will contain any failure information.
        """

        if kwargs.get('tx_id'):
            LOG.warning(
                _LW("%(tx_id)s Create VM Group failed %(result)s") % {
                    'tx_id': kwargs['tx_id'],
                    'result': kwargs['flow_failures']
                })
        else:
            LOG.warning(
                _LW("Create VM Group failed %s") % kwargs['flow_failures'])

        vm_group_info = kwargs.get('result')
        if vm_group_info and isinstance(vm_group_info, dict):
            try:
                vm_group_id = vm_group_info['id']
                if vm_group_id:
                    self.os_client.server_groups.delete(vm_group_id)
            except KeyError:
                pass
Example #2
0
    def revert(self, **kwargs):
        """Revert CreatePort Task

        This method is executed upon failure of the CreatePort Task or the Flow
        that the Task is part of.

        :param args: positional arguments that the task required to execute.
        :type args: list
        :param kwargs: keyword arguments that the task required to execute; the
                       special key `result` will contain the :meth:`execute`
                       results (if any) and the special key `flow_failures`
                       will contain any failure information.
        """
        if kwargs.get('tx_id'):
            LOG.warning(
                _LW("%(tx_id)s Create Port failed %(result)s") % {
                    'tx_id': kwargs['tx_id'],
                    'result': kwargs['flow_failures']
                })
        else:
            LOG.warning(_LW("Create Port failed %s") % kwargs['flow_failures'])

        port_info = kwargs.get('result')
        if (port_info and isinstance(port_info, dict) and 'port' in port_info
                and 'id' in port_info['port']):
            try:
                self.os_client.delete_port(port=port_info['port']['id'])
            except neutron_exc.PortNotFoundClient:
                # if port is not found, it was likely attached to a VM and
                # already deleted with the VM, so there's nothing to do
                pass
Example #3
0
def rmtree_without_raise(path):
    try:
        if os.path.isdir(path):
            shutil.rmtree(path)
    except OSError as e:
        LOG.warn(_LW("Failed to remove dir %(path)s, error: %(e)s"),
                {'path': path, 'e': e})
Example #4
0
def unlink_without_raise(path):
    try:
        os.unlink(path)
    except OSError as e:
        if e.errno == errno.ENOENT:
            return
        else:
            LOG.warn(_LW("Failed to unlink %(path)s, error: %(e)s"),
                        {'path': path, 'e': e})
Example #5
0
def create_link_without_raise(source, link):
    try:
        os.symlink(source, link)
    except OSError as e:
        if e.errno == errno.EEXIST:
            return
        else:
            LOG.warn(_LW("Failed to create symlink from %(source)s to %(link)s"
                         ", error: %(e)s"),
                         {'source': source, 'link': link, 'e': e})
Example #6
0
    def execute(self, group):
        """Main execute method

        :param name: ID of the server group to delete
        :type name: string
        :return: n/a
        """
        try:
            self.os_client.server_groups.delete(id=group)
        except nova_exc.NotFound:
            LOG.warning(_LW("Server group was not found %s") % group)
Example #7
0
    def execute(self, server, **kwargs):
        """Main execute method

        :param server: vm id to delete
        :type server: string
        :return: n/a
        """
        try:
            self.os_client.servers.delete(server=server)
        except nova_exc.NotFound:
            LOG.warning(_LW("VM was not found %s") % server)
Example #8
0
def safe_rstrip(value, chars=None):
    """Removes trailing characters from a string if that does not make it empty

    :param value: A string value that will be stripped.
    :param chars: Characters to remove.
    :return: Stripped value.

    """
    if not isinstance(value, six.string_types):
        LOG.warn(_LW("Failed to remove trailing character. Returning original "
                     "object. Supplied object is not a string: %s,"), value)
        return value

    return value.rstrip(chars) or value
Example #9
0
 def _delete_port(self, port_id):
     try:
         self.os_client.delete_port(port=port_id)
     except neutron_exc.NotFound:
         LOG.warning(_LW("Port was not found %s") % port_id)