Ejemplo n.º 1
0
static GList*
zapi_list_aggregates(na_server_t *s, GError **err)
{
	GList *la;
	na_elem_t *out, *in;
	na_elem_t *aggr_info_array, *aggr_info;
	na_elem_iter_t iter_aggr;

	XTRACE("Entering");

	in = na_elem_new("aggr-list-info");
	out = na_server_invoke_elem(s, in);
	na_elem_free(in);

	if (!out) {
		GSETERROR(err, "ZAPI error : no output");
		LOG_RETURN(NULL,"Failure (zapi error)");
	}
	if (na_results_status(out) != NA_OK) {
		na_elem_free(out);
		GSETERROR(err, "NetApp filer error : (%d) %s", na_results_errno(out), na_results_reason(out));
		LOG_RETURN(NULL,"Failure (server)");
	}

	la = NULL;
	aggr_info_array = na_elem_child(out, "aggregates");
	for (iter_aggr=na_child_iterator(aggr_info_array); (aggr_info=na_iterator_next(&iter_aggr)) ;) {
		const char *aname;
		aname = na_child_get_string(aggr_info,"name");
		la = g_list_append(la, g_strdup(aname));
	}
	
	na_elem_free(out);
	LOG_RETURN(la,"Success");
}
Ejemplo n.º 2
0
/* Retrieve a list of Aggregate-to-Volume list
 * covering all the aggregates of the given filer */
static GHashTable*
zapi_get_vol2aggr(na_server_t *s, GError **err)
{
	GHashTable *ht;
	na_elem_t *out, *in;
	na_elem_t *vol_info_array, *vol_info, *aggr_info_array, *aggr_info;
	na_elem_iter_t iter_aggr, iter_vol;

	XTRACE("Entering");
	
	/* the target aggregate is optional, and that is fine, we will
	 * get the information about all the agregates */
	in = na_elem_new("aggr-list-info");
	out = na_server_invoke_elem(s, in);
	na_elem_free(in);

	/* Error management */
	if (!out) {
		GSETERROR(err, "ZAPI error : no output");
		LOG_RETURN(NULL,"Failure (zapi error)");
	}
	if (na_results_status(out) != NA_OK) {
		na_elem_free(out);
		GSETERROR(err, "NetApp filer error : (%d) %s", na_results_errno(out), na_results_reason(out));
		LOG_RETURN(NULL,"Failure (server)");
	}

	/* Reply's content handling */
	ht = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
	aggr_info_array = na_elem_child(out, "aggregates");
	for (iter_aggr=na_child_iterator(aggr_info_array); (aggr_info=na_iterator_next(&iter_aggr)) ;) {
		vol_info_array = na_elem_child(aggr_info,"volumes");
		for (iter_vol=na_child_iterator(vol_info_array); (vol_info=na_iterator_next(&iter_vol)) ;) {
			const char *vname, *aname;

			vname = na_child_get_string(vol_info,"name");
			aname = na_child_get_string(aggr_info,"name");
			g_hash_table_insert(ht, g_strdup(vname), g_strdup(aname));
			XTRACE("Saved : vol[%s] -> agr[%s]", vname, aname);
		}
	}
	
	na_elem_free(out);
	LOG_RETURN(ht,"Success");
}
Ejemplo n.º 3
0
static GHashTable*
zapi_get_disk2aggr(na_server_t *s, GError **err)
{
	GHashTable *ht;
	na_elem_t *out, *in;
	na_elem_t *disk_info_array, *disk_info;
	na_elem_iter_t iter_disk;

	XTRACE("Entering");

	/* the target aggregate is optional, and that is fine, we will
	 * get the information about all the agregates */
	in = na_elem_new("disk-list-info");
	out = na_server_invoke_elem(s, in);

	/* Error management */
	if (!out) {
		na_elem_free(in);
		GSETERROR(err, "ZAPI error : no output");
		LOG_RETURN(NULL,"Failure (zapi error)");
	}
	if (na_results_status(out) != NA_OK) {
		na_elem_free(in);
		na_elem_free(out);
		GSETERROR(err, "NetApp filer error : (%d) %s", na_results_errno(out), na_results_reason(out));
		LOG_RETURN(NULL,"Failure (server)");
	}

	/* Reply's content handling */
	ht = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
	disk_info_array = na_elem_child(out,"disk-details");
	for (iter_disk=na_child_iterator(disk_info_array); (disk_info=na_iterator_next(&iter_disk)) ;) {
		const char *aname, *dname;

		/* normal case for flex-vol */
		aname = na_child_get_string(disk_info,"aggregate");
		
		if (!aname) /* special case for trad-vol volumes */
			aname = na_child_get_string(disk_info,"volume");
			
		if (aname) {
			dname = na_child_get_string(disk_info,"disk-uid");
		 	g_hash_table_insert(ht, g_strdup(dname), g_strdup(aname));
			XTRACE("Saved : disk[%s] -> aggr[%s]", dname, aname);
		}
	}
	
	na_elem_free(in);
	na_elem_free(out);
	LOG_RETURN(ht,"Success");
}
Ejemplo n.º 4
0
static GHashTable*
zapi_get_disk2idle(na_server_t *s, GError **err)
{
	GHashTable *ht;
	na_elem_t *out, *in;
	na_elem_t *instances, *instance;
	na_elem_iter_t iter_c, iter_i;

	XTRACE("Entering");

	in = na_elem_new("perf-object-get-instances");
	na_child_add_string(in, "objectname", "disk");

	do {
		na_elem_t *counters = na_elem_new("counters");
		na_child_add_string(counters, "counter", "disk_busy");
		na_child_add_string(counters, "counter", "base_for_disk_busy");
		na_child_add(in, counters);
	} while (0);

	out = na_server_invoke_elem(s, in);
	na_elem_free(in);
	
	/* Error management */
	if (!out) {
		GSETERROR(err, "ZAPI error : no output");
		LOG_RETURN(NULL,"Failure (zapi error)");
	}
	if (na_results_status(out) != NA_OK) {
		na_elem_free(out);
		GSETERROR(err, "NetApp filer error : (%d) %s", na_results_errno(out), na_results_reason(out));
		LOG_RETURN(NULL,"Failure (server)");
	}

	/* Reply's content handling */
	ht = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
	instances = na_elem_child(out, "instances");
	for (iter_i=na_child_iterator(instances); (instance = na_iterator_next(&iter_i)); ) {
		const char *iname;
		na_elem_t *counters, *counter;
		gint64 busy=1, busy_base=0;
		gint idle;

		iname = na_child_get_string(instance, "name");
		counters = na_elem_child(instance, "counters");

		for (iter_c=na_child_iterator(counters); (counter = na_iterator_next(&iter_c)) ; ) {
			const char *cname;
			gint i;

			cname = na_child_get_string(counter, "name");
			i = na_child_get_int(counter, "value", 0);
			if (cname && *cname=='b' && 0==g_ascii_strcasecmp(cname,"base_for_disk_busy"))
				busy_base = i>0 ? i : 1;
			if (cname && *cname=='d' && 0==g_ascii_strcasecmp(cname,"disk_busy"))
				busy = i>0 ? i : 1;
		}

		busy_base /= busy;
		idle = 100LL - busy_base;
		g_hash_table_insert(ht, g_strdup(iname), GINT_TO_POINTER(idle));
		XTRACE("Saved : disk[%s] -> idle[%d]", iname, idle);
	}
	
	na_elem_free(out);
	LOG_RETURN(ht,"Success");
}
Ejemplo n.º 5
0
int main(int argc, char* argv[])
{
	na_server_t*    s;
	na_elem_t       *out,*in;
	na_elem_t*	nextElem = NULL;
	na_elem_t*	iterList = NULL;
	na_elem_t*	counterList = NULL;
	na_elem_iter_t	iter, counterIter;
	char*           filerip    = argv[1];
	char*           user   	   = argv[2];
	char*           passwd 	   = argv[3];
	char*           operation  = argv[4];
	char            err[256];

	if (argc < 5) {
		print_usage();
	}

	// One-time initialization of system on client
	if (!na_startup(err, sizeof(err))) {
		fprintf(stderr, "Error in na_startup: %s\n", err);
		return -2;
	}

	//
	// Initialize connection to server, and request version 1.0 of the API set.
	//
	s = na_server_open(filerip, 1, 0);

	//
	// Set connection style (HTTPS)
	//
	na_server_style(s, NA_STYLE_LOGIN_PASSWORD);
	na_server_set_transport_type(s,NA_SERVER_TRANSPORT_HTTPS, NULL);
	na_server_set_port(s, 443);
	na_server_adminuser(s,user,passwd);

	if(!strcmp(operation, "object-list")) {
		in = na_elem_new("perf-object-list-info");
		out = na_server_invoke_elem(s,in);
		if (na_results_status(out) != NA_OK) {
			printf("Error %d: %s\n", na_results_errno(out),
			na_results_reason(out));
			na_elem_free(in);
			na_elem_free(out);
			na_server_close(s);
			na_shutdown();
			return -3;
		}
		iterList = na_elem_child(out, "objects");
		if(iterList == NULL) {
			// no data to list
			na_elem_free(in);
			na_elem_free(out);
			na_server_close(s);
			na_shutdown();
			return -3;
		}
		printf("\n-------------------------------------------------------\n");
		printf(" Object Name                           Privilege Level");
		printf("\n-------------------------------------------------------\n");
		for (iter=na_child_iterator(iterList); (nextElem =na_iterator_next(&iter)) != NULL;  ) {
			printf(" %-35s    %s\n",
			na_child_get_string(nextElem, "name"),
			na_child_get_string(nextElem, "privilege-level"));
		}
		printf("\n--------------------------------------------------------\n");

	}
	else if(!strcmp(operation, "instance-list")) {

		if( argc < 6) {
			printf("Usage:\n");
			printf("perf_operation <filer> <user> <password> <instance-list> <objectname>\n");
			return -1;
		}

		in = na_elem_new("perf-object-instance-list-info");
		na_child_add_string(in,"objectname",argv[5]);
		out = na_server_invoke_elem(s,in);
		if (na_results_status(out) != NA_OK) {
        	printf("Error %d: %s\n", na_results_errno(out),
			na_results_reason(out));
			na_elem_free(in);
			na_elem_free(out);
			na_server_close(s);
			na_shutdown();
			return -3;
		}
		iterList = na_elem_child(out, "instances");
		if(iterList == NULL) {
			// no data to list
			na_elem_free(in);
			na_elem_free(out);
			na_server_close(s);
			na_shutdown();
			return -3;
		}
		for (iter=na_child_iterator(iterList); (nextElem =na_iterator_next(&iter)) != NULL;  ) {
			printf("Instance Name = %s\n", na_child_get_string(nextElem, "name"));
		}

	}
	else if(!strcmp(operation, "counter-list")) {

		if( argc < 6) {
			printf("Usage:\n");
			printf("perf_operation <filer> <user> <password> <counter-list> <objectname>\n");
			return -1;
		}

		in = na_elem_new("perf-object-counter-list-info");
		na_child_add_string(in,"objectname",argv[5]);

		out = na_server_invoke_elem(s,in);
		if (na_results_status(out) != NA_OK) {
        	printf("Error %d: %s\n", na_results_errno(out),
			na_results_reason(out));
			na_elem_free(in);
			na_elem_free(out);
			na_server_close(s);
			na_shutdown();
			return -3;
		}
		iterList = na_elem_child(out, "counters");
		if(iterList == NULL) {
			// no data to list
			na_elem_free(in);
			na_elem_free(out);
			na_server_close(s);
			na_shutdown();
			return -3;
		}
		for (iter=na_child_iterator(iterList); (nextElem =na_iterator_next(&iter)) != NULL;  ) {

			printf("counter name: %s\n",na_child_get_string(nextElem, "name"));

			if(na_child_get_string(nextElem,"base-counter") != NULL) {
				printf("Base counter: %s\n",na_child_get_string(nextElem,"base-counter"));
			}
			else {
				printf("base counter: none\n");
			}
			printf("privilege-level: %s\n",na_child_get_string(nextElem,"privilege-level"));

			if(na_child_get_string(nextElem,"unit") != NULL) {
				printf("unit: %s\n",na_child_get_string(nextElem,"unit"));
			}
			else {
				printf("Unit: none\n");
			}
			printf("\n");
		}

	}
	else if(!strcmp(operation, "get-counter-values")) {

		int total_records = 0;
		int max_records = 10;
		int num_records = 0;
		char* iter_tag = NULL;
		na_elem_t *counters = NULL;
		int num_counter = 6;

		/* Here num_counter has been hard coded as 6 because first counter
			is specified at 7th position from cmd prompt */

		if( argc < 6) {
			printf("Usage:\n");
			printf("perf_operation <filer> <user> <password> ");
			printf("<get-counter-values> <objectname> [<counter1> <counter2> ..]\n");
			return -1;
		}

		in = na_elem_new("perf-object-get-instances-iter-start");
		na_child_add_string(in,"objectname",argv[5]);

		counters = na_elem_new("counters");

		/*Now store rest of the counter names as child element of counters */
		while(num_counter < argc) {
			na_child_add_string(counters, "counter",argv[num_counter]);
			num_counter++;
		}

		/* If no counters are specified then all the counters are fetched */
		if(num_counter > 6) {
			na_child_add(in,counters);
		}

		out = na_server_invoke_elem(s,in);
		if (na_results_status(out) != NA_OK) {
        	printf("Error %d: %s\n", na_results_errno(out),
			na_results_reason(out));
			na_elem_free(in);
			na_elem_free(out);
			na_server_close(s);
			na_shutdown();
			return -3;
		}
		total_records = na_child_get_int(out,"records",-1);
		iter_tag = (char *)na_child_get_string(out,"tag");

		do {
			in = na_elem_new("perf-object-get-instances-iter-next");
			na_child_add_string(in,"tag",iter_tag);
			na_child_add_int(in,"maximum", max_records);

			out = na_server_invoke_elem(s,in);
			if (na_results_status(out) != NA_OK) {
        		printf("Error %d: %s\n", na_results_errno(out),
				na_results_reason(out));
				na_elem_free(in);
				na_elem_free(out);
				na_server_close(s);
				na_shutdown();
        		return -3;
			}
			num_records = na_child_get_int(out,"records",0);

			if(num_records != 0) {
				iterList = na_elem_child(out, "instances");
				if(iterList == NULL) {
					// no data to list
					na_elem_free(in);
					na_elem_free(out);
					na_server_close(s);
					na_shutdown();
					return -3;
				}
				for (iter=na_child_iterator(iterList); (nextElem =na_iterator_next(&iter)) != NULL;  ) {
					printf("Instance = %s\n", na_child_get_string(nextElem,"name"));
					counterList = na_elem_child(nextElem,"counters");
					if(counterList == NULL) {
						// no data to list
						na_elem_free(in);
						na_elem_free(out);
						na_server_close(s);
						na_shutdown();
						return -3;
					}
					for (counterIter=na_child_iterator(counterList); (nextElem =na_iterator_next(&counterIter)) != NULL;  ) {
						printf("\ncounter name: %s\n",na_child_get_string(nextElem,"name"));
						printf("counter value: %s\n", na_child_get_string(nextElem,"value"));
					}
					printf("\n");
				}
			}
		} while (num_records != 0);

		in = na_elem_new("perf-object-get-instances-iter-end");
		na_child_add_string(in,"tag",iter_tag);
		out = na_server_invoke_elem(s,in);
		if (na_results_status(out) != NA_OK) {
			printf("Error %d: %s\n", na_results_errno(out), na_results_reason(out));
			na_elem_free(in);
			na_elem_free(out);
			na_server_close(s);
			na_shutdown();
			return -3;
		}
	}
	else {
		printf("Invalid Operation \n");
		print_usage();
	}
	na_elem_free(in);
	na_elem_free(out);
	na_server_close(s);
	na_shutdown();
	return 0;
}