def get_session_log(id): try: if not can_install(g.api_user): return failed_response('Not Authorized', return_code=HTTP_NOT_AUTHORIZED) return api_install.api_get_session_log(id) except Exception as e: return failed_response(e.message)
def jump_host_delete(hostname): try: if not can_delete(g.api_user): return failed_response('Not Authorized', return_code=HTTP_NOT_AUTHORIZED) return api_jump_host.api_delete_jump_host(hostname) except Exception as e: return failed_response(e.message)
def install_job_delete(): try: if not can_delete_install(g.api_user): return failed_response('Not Authorized', return_code=HTTP_NOT_AUTHORIZED) return api_install.api_delete_install_job(request) except Exception as e: return failed_response(e.message)
def custom_command_profile_delete(profile_name): try: if not can_delete(g.api_user): return failed_response('Not Authorized', return_code=HTTP_NOT_AUTHORIZED) return api_custom_command_profile.api_delete_custom_command_profile(profile_name) except Exception as e: return failed_response(e.message)
def server_repository_delete(hostname): try: if not can_delete(g.api_user): return failed_response('Not Authorized', return_code=HTTP_NOT_AUTHORIZED) else: return api_server_repository.api_delete_server_repositories(hostname) except Exception as e: return failed_response(e.message)
def region_delete(name): try: if not can_delete(g.api_user): return failed_response('Not Authorized', return_code=HTTP_NOT_AUTHORIZED) else: return api_region.api_delete_region(name) except Exception as e: return failed_response(e.message)
def server_repository_delete(hostname): try: if not can_delete(g.api_user): return failed_response('Not Authorized', return_code=HTTP_NOT_AUTHORIZED) else: return api_server_repository.api_delete_server_repositories( hostname) except Exception as e: return failed_response(e.message)
def api_hosts(): try: if request.method == 'POST': if not can_create(g.api_user): return failed_response('Not Authorized', return_code=HTTP_NOT_AUTHORIZED) return api_host.api_create_hosts(request) elif request.method == 'GET': return api_host.api_get_hosts(request) except Exception as e: return failed_response(e.message)
def custom_command_profile_delete(profile_name): try: if not can_delete(g.api_user): return failed_response('Not Authorized', return_code=HTTP_NOT_AUTHORIZED) return api_custom_command_profile.api_delete_custom_command_profile( profile_name) except Exception as e: return failed_response(e.message)
def api_get_cco_software(request): """ http://localhost:5000/api/v1/cco/software?platform=asr9k_px&release=5.3.3 """ validate_url_parameters(request, ['platform', 'release', 'date']) platform = request.args.get('platform') release = request.args.get('release') date = request.args.get('date') if date: date = datetime.datetime.strptime(date, "%m-%d-%Y") else: date = datetime.datetime.strptime('01-01-2000', "%m-%d-%Y") optimal = request.args.get('optimal') rows = [] smu_loader = SMUInfoLoader(platform, release) if smu_loader.is_valid: if optimal and optimal == 'false': smu_list = smu_loader.get_smu_list() sp_list = smu_loader.get_sp_list() else: smu_list = smu_loader.get_optimal_smu_list() sp_list = smu_loader.get_optimal_sp_list() for smu_info in smu_list: if datetime.datetime.strptime(smu_info.posted_date.split()[0], "%m/%d/%Y") >= date: rows.append(get_smu_info(smu_info)) for sp_info in sp_list: if datetime.datetime.strptime(sp_info.posted_date.split()[0], "%m/%d/%Y") >= date: rows.append(get_smu_info(sp_info)) if rows: return jsonify(**{RESPONSE_ENVELOPE: {'software_list': rows}}) return failed_response( ('Unable to get software information for platform {} ' + 'and release {}').format(platform, release))
def api_get_cco_software(request): """ http://localhost:5000/api/v1/cco/software?platform=asr9k_px&release=5.3.3 """ validate_url_parameters(request, ['platform', 'release', 'date']) platform = request.args.get('platform') release = request.args.get('release') date = request.args.get('date') if date: date = datetime.datetime.strptime(date, "%m-%d-%Y") else: date = datetime.datetime.strptime('01-01-2000', "%m-%d-%Y") optimal = request.args.get('optimal') rows = [] smu_loader = SMUInfoLoader(platform, release) if smu_loader.is_valid: if optimal and optimal == 'false': smu_list = smu_loader.get_smu_list() sp_list = smu_loader.get_sp_list() else: smu_list = smu_loader.get_optimal_smu_list() sp_list = smu_loader.get_optimal_sp_list() for smu_info in smu_list: if datetime.datetime.strptime(smu_info.posted_date.split()[0], "%m/%d/%Y") >= date: rows.append(get_smu_info(smu_info)) for sp_info in sp_list: if datetime.datetime.strptime(sp_info.posted_date.split()[0], "%m/%d/%Y") >= date: rows.append(get_smu_info(sp_info)) if rows: return jsonify(**{RESPONSE_ENVELOPE: {'software_list': rows}}) return failed_response(('Unable to get software information for platform {} ' + 'and release {}').format(platform, release))
def api_get_cco_software_entry(request, name_or_id): """ http://localhost:5000/api/v1/cco/software/AA09694?platform=asr9k_px&release=5.3.3 name_or_id can be the PIMS ID (e.g., AA09694) or the software name (asr9k-p-4.2.3.CSCut30136) """ validate_url_parameters(request, ['platform', 'release']) platform = request.args.get('platform') release = request.args.get('release') smu_loader = SMUInfoLoader(platform, release) if smu_loader.is_valid: smu_info = smu_loader.get_smu_info(name_or_id) if smu_info: return jsonify(**{RESPONSE_ENVELOPE: get_smu_info(smu_info)}) else: # Now search for the ID instead of name smu_info = smu_loader.get_smu_info_by_id(name_or_id) if smu_info: return jsonify(**{RESPONSE_ENVELOPE: get_smu_info(smu_info)}) return failed_response('Unable to locate {}'.format(name_or_id), return_code=HTTP_NOT_FOUND)
def api_get_hosts(request): """ GET: http://localhost:5000/api/v1/hosts http://localhost:5000/api/v1/hosts?hostname=Host_1 http://localhost:5000/api/v1/hosts?region=SJ Labs http://localhost:5000/api/v1/hosts?region=SJ Labs&page=2 http://localhost:5000/api/v1/hosts?region=SJ%20Labs&family=ASR9K """ validate_url_parameters(request, [KEY_HOSTNAME, KEY_REGION, KEY_FAMILY, 'page']) page = 1 clauses = [] db_session = DBSession hostname = request.args.get(KEY_HOSTNAME) if hostname: host = get_host(db_session, hostname) if host is None: raise ValueError( "Host '{}' does not exist in the database.".format(hostname)) hosts = [host] else: try: page = int( request.args.get('page')) if request.args.get('page') else 1 if page <= 0: page = 1 except Exception: return failed_response('page must be an numeric value') region_name = request.args.get(KEY_REGION) if region_name: region = get_region(db_session, region_name) if region: clauses.append(Host.region_id == region.id) else: return failed_response( "Region '{}' does not exist in the database.".format( region_name)) family = request.args.get(KEY_FAMILY) if family: clauses.append(Host.family == family) hosts = get_hosts_by_page(db_session, clauses, page) region_dict = get_region_id_to_name_dict(db_session) jump_host_dict = get_jump_host_id_to_name_dict(db_session) software_profile_dict = get_software_profile_id_to_name_dict(db_session) rows = [] for host in hosts: row = dict() row[KEY_HOSTNAME] = host.hostname row[KEY_REGION] = check_none(region_dict.get(host.region_id)) row[KEY_ROLES] = [] if is_empty(host.roles) else host.roles.split(',') connection_param = check_none(host.connection_param[0]) row[KEY_FAMILY] = check_none(host.family) row[KEY_CHASSIS] = check_none(host.platform) row[KEY_SOFTWARE_PLATFORM] = check_none(host.software_platform) row[KEY_SOFTWARE_VERSION] = check_none(host.software_version) row[KEY_OS_TYPE] = check_none(host.os_type) row[KEY_LOCATION] = check_none(host.location) row[KEY_SOFTWARE_PROFILE] = check_none( software_profile_dict.get(host.software_profile_id)) if connection_param: row[KEY_TS_OR_IP] = [] if is_empty( connection_param.host_or_ip ) else connection_param.host_or_ip.split(',') row[KEY_CONNECTION_TYPE] = check_none( connection_param.connection_type) row[KEY_USERNAME] = check_none(connection_param.username) row[KEY_PORT_NUMBER] = [] if is_empty( connection_param.port_number ) else connection_param.port_number.split(',') row[KEY_JUMP_HOST] = check_none( jump_host_dict.get(connection_param.jump_host_id)) rows.append(row) total_pages = get_total_pages(db_session, Host, clauses) return jsonify( **{ RESPONSE_ENVELOPE: { 'host_list': rows }, 'current_page': page, 'total_pages': total_pages })
def get_cco_catalog(): try: return api_cco.api_get_cco_catalog() except Exception as e: return failed_response(e.message)
def get_cco_software(): try: return api_cco.api_get_cco_software(request) except Exception as e: return failed_response(e.message)
def get_cco_software_entry(name_or_id): try: return api_cco.api_get_cco_software_entry(request, name_or_id) except Exception as e: return failed_response(e.message)