def add_backend(request): """Adds a new backend.""" params = request.json_body #remove spaces from start/end of string fields that are often included #when pasting keys, preventing thus succesfull connection with the #backend for key in params.keys(): if type(params[key]) in [unicode, str]: params[key] = params[key].rstrip().lstrip() title = params.get('title', '') provider = params.get('provider', '') apikey = params.get('apikey', '') apisecret = params.get('apisecret', '') apiurl = params.get('apiurl') or '' # fixes weird issue with none value tenant_name = params.get('tenant_name', '') # following params are for baremetal machine_hostname = params.get('machine_ip', '') machine_key = params.get('machine_key', '') machine_user = params.get('machine_user', '') remove_on_error = params.get('remove_on_error', True) try: docker_port = int(params.get('docker_port', 4243)) except: docker_port = 4243 try: ssh_port = int(params.get('machine_port', 22)) except: ssh_port = 22 region = params.get('region', '') compute_endpoint = params.get('compute_endpoint', '') # TODO: check if all necessary information was provided in the request user = user_from_request(request) backend_id = methods.add_backend( user, title, provider, apikey, apisecret, apiurl, tenant_name=tenant_name, machine_hostname=machine_hostname, machine_key=machine_key, machine_user=machine_user, region=region, compute_endpoint=compute_endpoint, port=ssh_port, docker_port=docker_port, remove_on_error=remove_on_error, ) backend = user.backends[backend_id] return { 'index': len(user.backends) - 1, 'id': backend_id, 'apikey': backend.apikey, 'apiurl': backend.apiurl, 'tenant_name': backend.tenant_name, 'title': backend.title, 'provider': backend.provider, 'poll_interval': backend.poll_interval, 'region': backend.region, 'status': 'off', 'enabled': backend.enabled, }
def add_backend(request): """Adds a new backend.""" params = request.json_body title = params.get('title', '') provider = params.get('provider', '') apikey = params.get('apikey', '') apisecret = params.get('apisecret', '') apiurl = params.get('apiurl') or '' # fixes weird issue with none value tenant_name = params.get('tenant_name', '') # following params are for baremetal machine_hostname = params.get('machine_ip', '') machine_key = params.get('machine_key', '') machine_user = params.get('machine_user', '') try: docker_port = int(params.get('docker_port', 4243)) except: docker_port = 4243 try: ssh_port = int(params.get('machine_port', 22)) except: ssh_port = 22 region = params.get('region', '') compute_endpoint = params.get('compute_endpoint', '') # TODO: check if all necessary information was provided in the request user = user_from_request(request) backend_id = methods.add_backend(user, title, provider, apikey, apisecret, apiurl, tenant_name=tenant_name, machine_hostname=machine_hostname, machine_key=machine_key, machine_user=machine_user, region=region, compute_endpoint=compute_endpoint, port=ssh_port, docker_port=docker_port) backend = user.backends[backend_id] return { 'index': len(user.backends) - 1, 'id': backend_id, 'apikey': backend.apikey, 'apiurl': backend.apiurl, 'tenant_name': backend.tenant_name, 'title': backend.title, 'provider': backend.provider, 'poll_interval': backend.poll_interval, 'region': backend.region, 'status': 'off', 'enabled': backend.enabled, }
def add_backend(request): """Adds a new backend.""" params = request.json_body title = params.get('title', '') provider = params.get('provider', '') apikey = params.get('apikey', '') apisecret = params.get('apisecret', '') apiurl = params.get('apiurl') or '' # fixes weird issue with none value tenant_name = params.get('tenant_name', '') # following params are for baremetal machine_hostname = params.get('machine_ip', '') machine_key = params.get('machine_key', '') machine_user = params.get('machine_user', '') remove_on_error = params.get('remove_on_error', True) try: docker_port = int(params.get('docker_port', 4243)) except: docker_port = 4243 try: ssh_port = int(params.get('machine_port', 22)) except: ssh_port = 22 region = params.get('region', '') compute_endpoint = params.get('compute_endpoint', '') # TODO: check if all necessary information was provided in the request user = user_from_request(request) backend_id = methods.add_backend( user, title, provider, apikey, apisecret, apiurl, tenant_name=tenant_name, machine_hostname=machine_hostname, machine_key=machine_key, machine_user=machine_user, region=region, compute_endpoint=compute_endpoint, port=ssh_port, docker_port=docker_port, remove_on_error=remove_on_error, ) backend = user.backends[backend_id] return { 'index': len(user.backends) - 1, 'id': backend_id, 'apikey': backend.apikey, 'apiurl': backend.apiurl, 'tenant_name': backend.tenant_name, 'title': backend.title, 'provider': backend.provider, 'poll_interval': backend.poll_interval, 'region': backend.region, 'status': 'off', 'enabled': backend.enabled, }
def add_backend(request): """Adds a new backend.""" params = request.json_body title = params.get('title', '') provider = params.get('provider', '') apikey = params.get('apikey', '') apisecret = params.get('apisecret', '') apiurl = params.get('apiurl') or '' # fixes weird issue with none value tenant_name = params.get('tenant_name', '') # following params are for baremetal machine_hostname = params.get('machine_ip', '') machine_key = params.get('machine_key', '') machine_user = params.get('machine_user', '') region = params.get('region', '') # TODO: check if all necessary information was provided in the request user = user_from_request(request) backend_id = methods.add_backend( user, title, provider, apikey, apisecret, apiurl, tenant_name=tenant_name, machine_hostname=machine_hostname, machine_key=machine_key, machine_user=machine_user, region=region ) backend = user.backends[backend_id] return { 'index': len(user.backends) - 1, 'id': backend_id, 'apikey': backend.apikey, 'apiurl': backend.apiurl, 'tenant_name': backend.tenant_name, 'title': backend.title, 'provider': backend.provider, 'poll_interval': backend.poll_interval, 'region': backend.region, 'status': 'off', 'enabled': backend.enabled, }
def add_backend(request): """Adds a new backend.""" params = request.json_body #remove spaces from start/end of string fields that are often included #when pasting keys, preventing thus succesfull connection with the #backend for key in params.keys(): if type(params[key]) in [unicode, str]: params[key] = params[key].rstrip().lstrip() api_version = request.headers.get('Api-Version', 1) title = params.get('title', '') provider = params.get('provider', '') if not provider: raise RequiredParameterMissingError('provider') user = user_from_request(request) monitoring = None if int(api_version) == 2: ret = methods.add_backend_v_2(user, title, provider, params) backend_id = ret['backend_id'] monitoring = ret.get('monitoring') else: apikey = params.get('apikey', '') apisecret = params.get('apisecret', '') apiurl = params.get('apiurl') or '' # fixes weird issue with none value tenant_name = params.get('tenant_name', '') # following params are for baremetal machine_hostname = params.get('machine_ip', '') machine_key = params.get('machine_key', '') machine_user = params.get('machine_user', '') remove_on_error = params.get('remove_on_error', True) try: docker_port = int(params.get('docker_port', 4243)) except: docker_port = 4243 try: ssh_port = int(params.get('machine_port', 22)) except: ssh_port = 22 region = params.get('region', '') compute_endpoint = params.get('compute_endpoint', '') # TODO: check if all necessary information was provided in the request backend_id = methods.add_backend( user, title, provider, apikey, apisecret, apiurl, tenant_name=tenant_name, machine_hostname=machine_hostname, machine_key=machine_key, machine_user=machine_user, region=region, compute_endpoint=compute_endpoint, port=ssh_port, docker_port=docker_port, remove_on_error=remove_on_error, ) backend = user.backends[backend_id] ret = { 'index': len(user.backends) - 1, 'id': backend_id, 'apikey': backend.apikey, 'apiurl': backend.apiurl, 'tenant_name': backend.tenant_name, 'title': backend.title, 'provider': backend.provider, 'poll_interval': backend.poll_interval, 'region': backend.region, 'status': 'off', 'enabled': backend.enabled, } if monitoring: ret['monitoring'] = monitoring return ret