def service_list(args, manager): current_service = find_service_by_arguments(manager, args.account, args.parent, args.path, args.simpleProps) if current_service is not None: child_services_result = manager.list_existing_service( [current_service.to_xml_friendly_object()], args.account) else: if args.service is not None or args.path is not None: raise Exception("Could not find the parent service.") else: child_services_result = manager.list_existing_service( None, args.account) list_result_list = [] if child_services_result.has_key( "ListExistingServicesResult" ) and child_services_result["ListExistingServicesResult"].children( ) is not None and len(child_services_result["ListExistingServicesResult"]. children()) > 0: for j in child_services_result["ListExistingServicesResult"].children( ): child_service = AtomiaService(show_simple_props=args.simpleProps) child_service.from_simplexml(j) list_result_list.append(child_service.to_print_friendly(False)) result = json_repr(list_result_list) ''' filter results ''' if args.filter is not None: from jsonpath_rw import jsonpath result = jsonpath.jsonpath(json.loads(result), args.filter) if args.first is True: if result: result = result[0] print json_repr(result).strip('"') else: print "" else: print json_repr(result) else: print result ''' else: raise Exception("No child services found for the service with logical id: " + current_service.logical_id) ''' return list_result_list
def service_list(args, manager): current_service = find_service_by_arguments(manager, args.account, args.parent, args.path, args.simpleProps) if current_service is not None: child_services_result = manager.list_existing_service([current_service.to_xml_friendly_object()], args.account) else: if args.service is not None or args.path is not None: raise Exception("Could not find the parent service.") else: child_services_result = manager.list_existing_service(None, args.account) list_result_list = [] if child_services_result.has_key("ListExistingServicesResult") and child_services_result["ListExistingServicesResult"].children() is not None and len(child_services_result["ListExistingServicesResult"].children()) > 0: for j in child_services_result["ListExistingServicesResult"].children(): child_service = AtomiaService(show_simple_props = args.simpleProps) child_service.from_simplexml(j) list_result_list.append(child_service.to_print_friendly(False)) result = json_repr(list_result_list) ''' filter results ''' if args.filter is not None: from jsonpath_rw import jsonpath result = jsonpath.jsonpath(json.loads(result), args.filter) if args.first is True: if result: result = result[0] print json_repr(result).strip('"') else: print "" else: print json_repr(result) else: print result ''' else: raise Exception("No child services found for the service with logical id: " + current_service.logical_id) ''' return list_result_list
def service_find(args, manager): if args.query is not None: find_options = json.loads(args.query) if isinstance(find_options, dict): if find_options.has_key('name'): service_name = find_options['name'] else: raise InputError("find_options argument must contain key name") relative_path = find_options['path'] if find_options.has_key('path') else '' result_page = find_options['page'] if find_options.has_key('page') else '0' result_count = find_options['count'] if find_options.has_key('count') else '100' if find_options.has_key('properties'): if isinstance(find_options['properties'], dict): service_properties = find_options['properties'] else: raise InputError("Invalid format of the properties key") else: service_properties = None else: raise InputError("Invalid format of query argument.") else: raise InputError("query is required argument for this action.") parent_service = find_service_by_arguments(manager, args.account, args.parent, args.path, args.simpleProps) service_search_criteria_list = [] search_properties = [] if parent_service is not None: tmp_ssc = AtomiaServiceSearchCriteria(service_name, relative_path, parent_service) else: tmp_ssc = AtomiaServiceSearchCriteria(service_name, relative_path) service_search_criteria_list.append(tmp_ssc.to_xml_friendly_object('atom:ServiceSearchCriteria', 'ServiceSearchCriteria')) if service_properties is not None: for propk in service_properties: tmp_property = AtomiaServiceSearchCriteriaProperty(str(propk), str(service_properties[propk])) search_properties.append(tmp_property.to_xml_friendly_object('arr:KeyValueOfstringstring', 'KeyValueOfstringstring')) find_action_res = manager.find_services_by_path_with_paging(service_search_criteria_list, args.account, search_properties=search_properties, page_number=result_page, page_size = result_count) find_result_list = [] if find_action_res.itervalues().next() is not None and find_action_res.itervalues().next().children() is not None: for k in find_action_res.itervalues().next().children(): find_action_result = AtomiaService(show_simple_props = args.simpleProps) find_action_result.from_simplexml(k) find_result_list.append(find_action_result.to_print_friendly(False, True)) result = json_repr(find_result_list) ''' filter results ''' if args.filter is not None: import jsonpath result = jsonpath.jsonpath(json.loads(result), args.filter) if args.first is True: if result: result = result[0] print json_repr(result).strip('"') else: print "" else: print json_repr(result) else: print result ''' else: raise Exception("Could not find service: " + service_name) ''' return find_result_list
def service_find(args, manager): if args.query is not None: find_options = json.loads(args.query) if isinstance(find_options, dict): if find_options.has_key('name'): service_name = find_options['name'] else: raise InputError("find_options argument must contain key name") relative_path = find_options['path'] if find_options.has_key( 'path') else '' result_page = find_options['page'] if find_options.has_key( 'page') else '0' result_count = find_options['count'] if find_options.has_key( 'count') else '100' if find_options.has_key('properties'): if isinstance(find_options['properties'], dict): service_properties = find_options['properties'] else: raise InputError("Invalid format of the properties key") else: service_properties = None else: raise InputError("Invalid format of query argument.") else: raise InputError("query is required argument for this action.") parent_service = find_service_by_arguments(manager, args.account, args.parent, args.path, args.simpleProps) service_search_criteria_list = [] search_properties = [] if parent_service is not None: tmp_ssc = AtomiaServiceSearchCriteria(service_name, relative_path, parent_service) else: tmp_ssc = AtomiaServiceSearchCriteria(service_name, relative_path) service_search_criteria_list.append( tmp_ssc.to_xml_friendly_object('atom:ServiceSearchCriteria', 'ServiceSearchCriteria')) if service_properties is not None: for propk in service_properties: tmp_property = AtomiaServiceSearchCriteriaProperty( str(propk), str(service_properties[propk])) search_properties.append( tmp_property.to_xml_friendly_object( 'arr:KeyValueOfstringstring', 'KeyValueOfstringstring')) find_action_res = manager.find_services_by_path_with_paging( service_search_criteria_list, args.account, search_properties=search_properties, page_number=result_page, page_size=result_count) find_result_list = [] if find_action_res.itervalues().next( ) is not None and find_action_res.itervalues().next().children( ) is not None: for k in find_action_res.itervalues().next().children(): find_action_result = AtomiaService( show_simple_props=args.simpleProps) find_action_result.from_simplexml(k) find_result_list.append( find_action_result.to_print_friendly(False, True)) result = json_repr(find_result_list) ''' filter results ''' if args.filter is not None: import jsonpath result = jsonpath.jsonpath(json.loads(result), args.filter) if args.first is True: if result: result = result[0] print json_repr(result).strip('"') else: print "" else: print json_repr(result) else: print result ''' else: raise Exception("Could not find service: " + service_name) ''' return find_result_list