コード例 #1
0
ファイル: wsmand-daemon.c プロジェクト: JamesTryand/openwsman
int wsmand_parse_options(int argc, char **argv)
{
	char retval;
	u_option_context_t *opt_ctx;
	u_error_t *error = NULL;
	char *version = NULL;

	u_option_entry_t options[] = {
#if 0
		{"no-plugins", 'n', U_OPTION_ARG_NONE, &no_plugin_flag,
		 "Do not load any plugins", NULL},
#endif
		{"ssl", 'S', U_OPTION_ARG_NONE, &use_ssl,
		 "Use SSL port", NULL},
		{"version", 'q', U_OPTION_ARG_NONE, &version,
		 "Display application version", NULL},
		{"debug", 'd', U_OPTION_ARG_NONE, &foreground_debug,
		 "Start daemon in foreground and turn on debugging", NULL},
		{"syslog", 's', U_OPTION_ARG_INT, &syslog_level,
		 "Set the verbosity of syslog output.", "0-6"},
		{"enum-idle-timeout", 'e', U_OPTION_ARG_INT,
		 &enumIdleTimeout,
		 "Enumeration Idle timeout in secs", "default 100"},
		{"config-file", 'c', U_OPTION_ARG_STRING, &config_file,
		 "Alternate configuration file", "<file>"},
		{"pid-file", 'p', U_OPTION_ARG_STRING, &pid_file,
		 "PID file", "<file>"},
		{"subscription-repository-location", 'r',  U_OPTION_ARG_STRING, &uri_subscription_repository,
		"Subscription Repository Location", "<uri>"},
		{NULL}
	};

	wsmand_argv = (const char **) argv;
	opt_ctx = u_option_context_new("WS-Management Server");
	u_option_context_set_ignore_unknown_options(opt_ctx, FALSE);
	u_option_context_add_main_entries(opt_ctx, options, "wsman");
	retval = u_option_context_parse(opt_ctx, &argc, &argv, &error);
	if (error) {
		if (error->message)
			printf("%s\n", error->message);
		retval = 0;
	}
	if (version) {
		fprintf(stdout, PACKAGE_NAME " " PACKAGE_VERSION " (" PACKAGE_BUILDTS ")\n\n");
		exit(0);
	}
	
	u_error_free(error);
	u_option_context_free(opt_ctx);
	return retval;
}
コード例 #2
0
int main(int argc, char **argv)
{
	int num;
	int i;
	char retval = 0;
	u_error_t *error = NULL;
	u_option_entry_t opt[] = {
		{"debug", 'd', U_OPTION_ARG_INT, &debug_level,
		 "Set the verbosity of debugging output.", "1-6"}
	};
	u_option_context_t *opt_ctx;
	opt_ctx = u_option_context_new("");
	u_option_context_set_ignore_unknown_options(opt_ctx, FALSE);
	u_option_context_add_main_entries(opt_ctx, opt, "wsmid_identify");
	retval = u_option_context_parse(opt_ctx, &argc, &argv, &error);

	u_option_context_free(opt_ctx);

	if (error) {
		if (error->message)
			printf("%s\n", error->message);
		u_error_free(error);
		return 1;
	}
	u_error_free(error);

	if (debug_level) {
		initialize_logging();
		wsman_debug_set_level(debug_level);
	}

	if (argc == 1) {
		// execute all
		example1();
		example2();
		example3();
		example4();
		example5();
		example6();
		example7();
		example8();
		example9();
		example10();
		example11();
		example12();
		example13();
		example14();
		return 0;
	}

	for (i = 1; i < argc; i++) {
		num = atoi(argv[i]);
		switch (num) {
		case 1:
			example1();
			break;
		case 2:
			example2();
			break;
		case 3:
			example3();
			break;
		case 4:
			example4();
			break;
	        case 5: 
			example5(); 
			break;
		case 6:
			example6();
			break;
		case 7:
			example7();
			break;
		case 8:
			example8();
			break;
		case 9:
			example9();
			break;
		case 10:
			example10();
			break;
		case 11:
			example11();
			break;
		case 12:
			example12();
			break;
		case 13:
			example13();
			break;
		case 14:
			example14();
			break;
		default:
			printf("\n    No example%d()\n", num);
			break;
		}
	}
	return 0;
}
コード例 #3
0
ファイル: session_invoke.c プロジェクト: Openwsman/wsmancli
int main(int argc, char** argv)
{
	int		sid;
	int		eid;
	char		*response;
	char 		retval = 0;
	const char	*resource_uri =
	"http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_SystemTimeService";
	u_error_t 	*error = NULL;
	char		*user = NULL;
	char		*passwd = NULL;

	u_option_entry_t opt[] = {
	{ "user",	'u',	U_OPTION_ARG_STRING,	&user,
		"user name", "<user>" },
	{ "passwd",	'p',	U_OPTION_ARG_STRING,	&passwd,
		"password", "<passwd>" },
	{ NULL }
	};


	u_option_context_t *opt_ctx;	
	opt_ctx = u_option_context_new("");
	u_option_context_set_ignore_unknown_options(opt_ctx, FALSE);
	u_option_context_add_main_entries(opt_ctx, opt, "adv api example");
	retval = u_option_context_parse(opt_ctx, &argc, &argv, &error);
	u_option_context_free(opt_ctx);

	if (error) {
		if (error->message)
		printf ("%s\n", error->message);
		u_error_free(error);
		return 0;
	}
	u_error_free(error);

	if (!user || !passwd) {
		printf("\t new_api_example: user and passwd are required\n");
		return 0;
	}

	sid = wsman_session_open("localhost", 8889, "/wsman", "http",
				user, passwd, 0);

	if (sid < 0) {
		printf("Open session failed\n");
		return 0;
	}


	printf("\n******** Opened session id %d ********\n\n", sid);

	eid = wsman_session_enumerate(sid, resource_uri, NULL, NULL,
						FLAG_ENUMERATION_ENUM_EPR);

	if (eid < 0) {
		printf("******** Enumeration failed - %s ********\n\n",
			wsman_session_error(sid));
		goto end;
	}

	response = wsman_enumerator_pull(eid);
	if (!response) {
		printf("******** Pull failed - %s ********\n\n",
			wsman_enumerator_error(eid));
	}

	wsman_enumerator_release(eid);

	wsman_session_resource_locator_set(sid, response);

	response = wsman_session_invoke(sid, "ManageSystemTime",
					"<GetRequest>TRUE</GetRequest>", 0);

	if (!response) {
		printf("******** Invoke failed - %s ********\n\n",
			wsman_session_error(sid));
		goto end;
	}
	printf("******** Invoke response *******\n%s\n", response);
	retval = 1;

 end:
	wsman_session_close(sid);
	printf("******** Closed session id %d ********\n\n", sid);

	return retval;
}