Пример #1
0
 def test_environment_create(self, mock_log, mock_api):
     parameters = {
         'name': 'test_env',
         'defaultNetworks': 'test_net'
     }
     env_api.environment_create(self.mock_request, parameters)
     env_api.api.muranoclient.assert_called_with(self.mock_request)
     self.assertTrue(mock_log.debug.called)
Пример #2
0
 def test_environment_create(self, mock_log, mock_api):
     parameters = {
         'name': 'test_env',
         'defaultNetworks': 'test_net'
     }
     env_api.environment_create(self.mock_request, parameters)
     env_api.api.muranoclient.assert_called_with(self.mock_request)
     self.assertTrue(mock_log.debug.called)
Пример #3
0
 def action(self, request, environment):
     try:
         api.environment_create(request, environment)
     except Exception as e:
         msg = (_('Unable to create environment {0}'
                  ' due to: {1}').format(environment, e))
         LOG.error(msg)
         redirect = reverse(self.redirect_url)
         exceptions.handle(request, msg, redirect=redirect)
Пример #4
0
 def action(self, request, environment):
     try:
         api.environment_create(request, environment)
     except Exception as e:
         msg = (_('Unable to create environment {0}'
                  ' due to: {1}').format(environment, e))
         LOG.error(msg)
         redirect = reverse(self.redirect_url)
         exceptions.handle(request, msg, redirect=redirect)
Пример #5
0
 def handle(self, request, context):
     try:
         api.environment_create(request, context)
         return True
     except Exception:
         name = self.context.get('name', 'noname')
         LOG.error("Unable to create environment {0}".format(name))
         exceptions.handle(request)
         return False
Пример #6
0
 def handle(self, request, context):
     try:
         environment = api.environment_create(request, context)
         context['environment_id'] = environment.id
         return True
     except exc.HTTPConflict:
         msg = "Environment with specified name already exists"
         LOG.error("Environment with specified name is already exist")
         exceptions.handle(request, msg)
         return False
     except Exception:
         name = self.context.get('name', 'noname')
         LOG.error("Unable to create environment {0}".format(name))
         exceptions.handle(request, ignore=True)
         return False
Пример #7
0
def create_quick_environment(request):
    quick_env_prefix = 'quick-env-'
    quick_env_re = re.compile('^' + quick_env_prefix + '([\d]+)$')

    def parse_number(env):
        match = re.match(quick_env_re, env.name)
        return int(match.group(1)) if match else 0

    numbers = [parse_number(e) for e in api.environments_list(request)]
    new_env_number = 1
    if numbers:
        numbers.sort()
        new_env_number = numbers[-1] + 1

    params = {'name': quick_env_prefix + str(new_env_number)}
    return api.environment_create(request, params)
Пример #8
0
 def handle(self, request, data):
     try:
         env = api.environment_create(request, data)
         request.session['env_id'] = env.id
         messages.success(request,
                          'Created environment "{0}"'.format(data['name']))
         return True
     except exc.HTTPConflict:
         msg = _('Environment with specified name already exists')
         LOG.exception(msg)
         exceptions.handle(request, ignore=True)
         messages.error(request, msg)
         return False
     except Exception:
         msg = _('Failed to create environment')
         LOG.exception(msg)
         exceptions.handle(request)
         messages.error(request, msg)
         return False
 def handle(self, request, data):
     try:
         net_config = ast.literal_eval(data.pop('net_config'))
         if net_config[0] is not None:
             data.update(net.generate_join_existing_net(net_config))
         env = api.environment_create(request, data)
         request.session['env_id'] = env.id
         messages.success(request,
                          u'Created environment "{0}"'.format(data['name']))
         return True
     except exc.HTTPConflict:
         msg = _('Environment with specified name already exists')
         LOG.exception(msg)
         exceptions.handle(request, ignore=True)
         messages.error(request, msg)
         return False
     except Exception:
         msg = _('Failed to create environment')
         LOG.exception(msg)
         exceptions.handle(request)
         messages.error(request, msg)
         return False
Пример #10
0
 def handle(self, request, data):
     try:
         net_config = ast.literal_eval(data.pop('net_config'))
         if net_config[0] is not None:
             data.update(net.generate_join_existing_net(net_config))
         env = api.environment_create(request, data)
         request.session['env_id'] = env.id
         messages.success(request,
                          u'Created environment "{0}"'.format(data['name']))
         return True
     except exc.HTTPConflict:
         msg = _('Environment with specified name already exists')
         LOG.exception(msg)
         exceptions.handle(request, ignore=True)
         messages.error(request, msg)
         return False
     except Exception:
         msg = _('Failed to create environment')
         LOG.exception(msg)
         exceptions.handle(request)
         messages.error(request, msg)
         return False
Пример #11
0
def create_quick_environment(request):
    params = {'name': get_next_quick_environment_name(request)}
    return env_api.environment_create(request, params)
Пример #12
0
def create_quick_environment(request):
    params = {'name': get_next_quick_environment_name(request)}
    return env_api.environment_create(request, params)
Пример #13
0
 def action(self, request, environment):
     api.environment_create(request, environment)