Пример #1
0
    def create_wait(self, plugin, context, device_dict, device_id, auth_attr):
        region_name = device_dict.get('placement_attr',
                                      {}).get('region_name', None)
        heatclient_ = HeatClient(auth_attr, region_name)

        stack = heatclient_.get(device_id)
        status = stack.stack_status
        stack_retries = STACK_RETRIES
        error_reason = None
        while status == 'CREATE_IN_PROGRESS' and stack_retries > 0:
            time.sleep(STACK_RETRY_WAIT)
            try:
                stack = heatclient_.get(device_id)
            except Exception:
                LOG.exception(
                    _("Device Instance cleanup may not have "
                      "happened because Heat API request failed "
                      "while waiting for the stack %(stack)s to be "
                      "deleted"), {'stack': device_id})
                break
            status = stack.stack_status
            LOG.debug(_('status: %s'), status)
            stack_retries = stack_retries - 1

        LOG.debug(_('stack status: %(stack)s %(status)s'), {
            'stack': str(stack),
            'status': status
        })
        if stack_retries == 0 and status != 'CREATE_COMPLETE':
            error_reason = _("Resource creation is not completed within"
                             " {wait} seconds as creation of stack {stack}"
                             " is not completed").format(
                                 wait=(STACK_RETRIES * STACK_RETRY_WAIT),
                                 stack=device_id)
            LOG.warning(_("VNF Creation failed: %(reason)s"),
                        {'reason': error_reason})
            raise vnfm.DeviceCreateWaitFailed(device_id=device_id,
                                              reason=error_reason)

        elif stack_retries != 0 and status != 'CREATE_COMPLETE':
            error_reason = stack.stack_status_reason
            raise vnfm.DeviceCreateWaitFailed(device_id=device_id,
                                              reason=error_reason)

        outputs = stack.outputs
        LOG.debug(_('outputs %s'), outputs)
        PREFIX = 'mgmt_ip-'
        mgmt_ips = dict(
            (output['output_key'][len(PREFIX):], output['output_value'])
            for output in outputs
            if output.get('output_key', '').startswith(PREFIX))
        if mgmt_ips:
            device_dict['mgmt_url'] = jsonutils.dumps(mgmt_ips)
Пример #2
0
    def delete_wait(self,
                    plugin,
                    context,
                    device_id,
                    auth_attr,
                    region_name=None):
        heatclient_ = HeatClient(auth_attr, region_name)

        stack = heatclient_.get(device_id)
        status = stack.stack_status
        error_reason = None
        stack_retries = STACK_RETRIES
        while (status == 'DELETE_IN_PROGRESS' and stack_retries > 0):
            time.sleep(STACK_RETRY_WAIT)
            try:
                stack = heatclient_.get(device_id)
            except heatException.HTTPNotFound:
                return
            except Exception:
                LOG.exception(
                    _("Device Instance cleanup may not have "
                      "happened because Heat API request failed "
                      "while waiting for the stack %(stack)s to be "
                      "deleted"), {'stack': device_id})
                break
            status = stack.stack_status
            stack_retries = stack_retries - 1

        if stack_retries == 0 and status != 'DELETE_COMPLETE':
            error_reason = _("Resource cleanup for device is"
                             " not completed within {wait} seconds as "
                             "deletion of Stack {stack} is "
                             "not completed").format(stack=device_id,
                                                     wait=(STACK_RETRIES *
                                                           STACK_RETRY_WAIT))
            LOG.warning(error_reason)
            raise vnfm.DeviceCreateWaitFailed(device_id=device_id,
                                              reason=error_reason)

        if stack_retries != 0 and status != 'DELETE_COMPLETE':
            error_reason = _("device {device_id} deletion is not completed. "
                             "{stack_status}").format(device_id=device_id,
                                                      stack_status=status)
            LOG.warning(error_reason)
            raise vnfm.DeviceCreateWaitFailed(device_id=device_id,
                                              reason=error_reason)
Пример #3
0
    def create_wait(self, plugin, context, device_dict, device_id):
        heatclient_ = HeatClient(context)

        stack = heatclient_.get(device_id)
        status = stack.stack_status
        stack_retries = STACK_RETRIES
        while status == 'CREATE_IN_PROGRESS' and stack_retries > 0:
            time.sleep(STACK_RETRY_WAIT)
            try:
                stack = heatclient_.get(device_id)
            except Exception:
                LOG.exception(
                    _("Device Instance cleanup may not have "
                      "happened because Heat API request failed "
                      "while waiting for the stack %(stack)s to be "
                      "deleted"), {'stack': device_id})
                break
            status = stack.stack_status
            LOG.debug(_('status: %s'), status)
            stack_retries = stack_retries - 1

        LOG.debug(_('stack status: %(stack)s %(status)s'), {
            'stack': str(stack),
            'status': status
        })
        if stack_retries == 0:
            LOG.warning(
                _("Resource creation is"
                  " not completed within %(wait)s seconds as "
                  "creation of Stack %(stack)s is not completed"), {
                      'wait': (STACK_RETRIES * STACK_RETRY_WAIT),
                      'stack': device_id
                  })
        if status != 'CREATE_COMPLETE':
            raise vnfm.DeviceCreateWaitFailed(device_id=device_id)
        outputs = stack.outputs
        LOG.debug(_('outputs %s'), outputs)
        PREFIX = 'mgmt_ip-'
        mgmt_ips = dict(
            (output['output_key'][len(PREFIX):], output['output_value'])
            for output in outputs
            if output.get('output_key', '').startswith(PREFIX))
        if mgmt_ips:
            device_dict['mgmt_url'] = jsonutils.dumps(mgmt_ips)