'Create the resource.
Subclasses should provide a handle_create() method to customise
creation.'

@scheduler.wrappertask
def create(self):

    action = self.CREATE
    if ((self.action, self.status) != (self.INIT, self.COMPLETE)):
        exc = exception.Error((_('State    %s    invalid    for    create') % six.text_type(self.state)))
        raise exception.ResourceFailure(exc, self, action)
    if (self.external_id is not None):
        (yield self._do_action(self.ADOPT, resource_data={'resource_id': self.external_id}))
        self.check()
        return
    if (self.stack.action == self.stack.CREATE):
        (yield self._break_if_required(self.CREATE, environment.HOOK_PRE_CREATE))
    LOG.info('creating    %s', self)
    self.reparse()
    self._update_stored_properties()
    count = {self.CREATE: 0, self.DELETE: 0}
    retry_limit = max(cfg.CONF.action_retry_limit, 0)
    first_failure = None
    while ((count[self.CREATE] <= retry_limit) and (count[self.DELETE] <= retry_limit)):
        pre_func = None
        if (count[action] > 0):
            delay = timeutils.retry_backoff_delay(count[action], jitter_max=2.0)
            waiter = scheduler.TaskRunner(self.pause)
            (yield waiter.as_task(timeout=delay))
        elif (action == self.CREATE):
            pre_func = self.properties.validate
        try:
            (yield self._do_action(action, pre_func))
            if (action == self.CREATE):
                first_failure = None
                break
            else:
                action = self.CREATE
        except exception.ResourceFailure as failure:
            if isinstance(failure.exc, exception.StackValidationFailed):
                path = [self.t.name]
                path.extend(failure.exc.path)
                raise exception.ResourceFailure(exception_or_error=exception.StackValidationFailed(error=failure.exc.error, path=path, message=failure.exc.error_message), resource=failure.resource, action=failure.action)
            if (not isinstance(failure.exc, exception.ResourceInError)):
                raise failure
            count[action] += 1
            if (action == self.CREATE):
                action = self.DELETE
                count[action] = 0
            if (first_failure is None):
                first_failure = failure
    if first_failure:
        raise first_failure
    if (self.stack.action == self.stack.CREATE):
        (yield self._break_if_required(self.CREATE, environment.HOOK_POST_CREATE))
