summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDenis Sadykov <sadden@intel.com>2007-03-14 11:55:56 +0000
committerDenis Sadykov <sadden@intel.com>2007-03-14 11:55:56 +0000
commit029eaaf924e390915f73b92fde5bc2fdf842de54 (patch)
tree154e8c3167f434dbe0f0b9fa2a3f392460332cc4 /examples
parent96665f9bf67675e09a8c3e59ee3b1cd3f26e98e3 (diff)
downloadwsmancli-029eaaf924e390915f73b92fde5bc2fdf842de54.tar.gz
wsmancli-029eaaf924e390915f73b92fde5bc2fdf842de54.tar.xz
wsmancli-029eaaf924e390915f73b92fde5bc2fdf842de54.zip
new api examples update
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am12
-rw-r--r--examples/new_api_example.c56
-rw-r--r--examples/new_api_invoke.c90
-rw-r--r--examples/new_api_transfer_create.c2
-rw-r--r--examples/new_api_transfer_get_put.c105
5 files changed, 215 insertions, 50 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index f34d31a..4adda7f 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -23,8 +23,15 @@ create_resource_SOURCES = \
new_api_example_SOURCES = \
new_api_example.c
+
new_api_transfer_create_SOURCES = \
new_api_transfer_create.c
+
+new_api_invoke_SOURCES = \
+ new_api_invoke.c
+
+new_api_transfer_get_put_SOURCES = \
+ new_api_transfer_get_put.c
noinst_PROGRAMS = \
wsmid_identify \
@@ -33,7 +40,8 @@ noinst_PROGRAMS = \
create_resource \
serialize \
new_api_example \
- new_api_transfer_create
-
+ new_api_transfer_create \
+ new_api_invoke \
+ new_api_transfer_get_put
diff --git a/examples/new_api_example.c b/examples/new_api_example.c
index bae55f6..da4bb08 100644
--- a/examples/new_api_example.c
+++ b/examples/new_api_example.c
@@ -3,9 +3,6 @@
int main(int argc, char** argv)
{
int sid;
- int eid;
- int sid1;
- int i = 0;
char *response;
char retval = 0;
const char *resource_uri =
@@ -34,13 +31,13 @@ int main(int argc, char** argv)
if (error->message)
printf ("%s\n", error->message);
u_error_free(error);
- return 1;
+ return 0;
}
u_error_free(error);
if (!user || !passwd) {
printf("\t new_api_example: user and passwd are required\n");
- return 1;
+ return 0;
}
sid = wsman_session_open("localhost", 8889, "/wsman", "http",
@@ -54,52 +51,17 @@ int main(int argc, char** argv)
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",
+ response = wsman_session_identify(sid, 0);
+ if (!response) {
+ printf("******** Identify failed - %s ********\n\n",
wsman_session_error(sid));
- return 0;
- }
-
- while (wsman_enumerator_end(eid)) {
- i++;
- response = wsman_enumerator_pull(eid);
- if (!response) {
- printf("******** Pull (%d) failed - %s ********\n\n",
- i, wsman_session_error(eid));
- break;
- }
- printf("******** Pull response (%d) *******\n%s\n", i,
- response);
- sid1 = wsman_session_resource_locator_new(sid, response);
- response = wsman_session_transfer_get(sid1, 0);
-
- if (!response) {
- printf("******** Transfer Get failed - %s ********\n\n",
- wsman_session_error(sid1));
- goto continuep;
- }
- printf ("******** Transfer Get response ********\n%s\n",
- response);
-
- response = wsman_session_transfer_put(sid1, response, 0);
-
- if (!response) {
- printf("******** Transfer Put failed - %s ********\n\n",
- wsman_session_error(sid1));
- goto continuep;
- }
- printf ("******** Transfer Put response ********\n%s\n",
- response);
- continuep:
- wsman_session_close(sid1);
+ goto end;
}
+ printf("******** Identify response *******\n%s\n", response);
+ end:
wsman_session_close(sid);
-
printf("******** Closed session id %d ********\n\n", sid);
- return 1;
+ return retval;
}
diff --git a/examples/new_api_invoke.c b/examples/new_api_invoke.c
new file mode 100644
index 0000000..ff7ebc1
--- /dev/null
+++ b/examples/new_api_invoke.c
@@ -0,0 +1,90 @@
+#include "wsman-client-api.h"
+
+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;
+}
diff --git a/examples/new_api_transfer_create.c b/examples/new_api_transfer_create.c
index 185fad4..a46593d 100644
--- a/examples/new_api_transfer_create.c
+++ b/examples/new_api_transfer_create.c
@@ -97,7 +97,7 @@ int main(int argc, char** argv)
printf("\n******** Opened session id %d ********\n\n", sid);
res = wsman_session_serialize(sid, d, EXL_ExamplePolicy_TypeInfo);
-printf("%s\n", res);
+
res = wsman_session_transfer_create(sid, res, 0);
if (!res) {
diff --git a/examples/new_api_transfer_get_put.c b/examples/new_api_transfer_get_put.c
new file mode 100644
index 0000000..0cedd13
--- /dev/null
+++ b/examples/new_api_transfer_get_put.c
@@ -0,0 +1,105 @@
+#include "wsman-client-api.h"
+
+int main(int argc, char** argv)
+{
+ int sid;
+ int eid;
+ int sid1;
+ int i = 0;
+ char *response;
+ char retval = 0;
+ const char *resource_uri =
+ "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem";
+ 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 1;
+ }
+ u_error_free(error);
+
+ if (!user || !passwd) {
+ printf("\t new_api_example: user and passwd are required\n");
+ return 1;
+ }
+
+ 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));
+ return 0;
+ }
+
+ while (wsman_enumerator_end(eid)) {
+ i++;
+ response = wsman_enumerator_pull(eid);
+ if (!response) {
+ printf("******** Pull (%d) failed - %s ********\n\n",
+ i, wsman_enumerator_error(eid));
+ break;
+ }
+ printf("******** Pull response (%d) *******\n%s\n", i,
+ response);
+ sid1 = wsman_session_resource_locator_new(sid, response);
+ response = wsman_session_transfer_get(sid1, 0);
+
+ if (!response) {
+ printf("******** Transfer Get failed - %s ********\n\n",
+ wsman_session_error(sid1));
+ goto continuep;
+ }
+ printf ("******** Transfer Get response ********\n%s\n",
+ response);
+
+ response = wsman_session_transfer_put(sid1, response, 0);
+
+ if (!response) {
+ printf("******** Transfer Put failed - %s ********\n\n",
+ wsman_session_error(sid1));
+ goto continuep;
+ }
+ printf ("******** Transfer Put response ********\n%s\n",
+ response);
+ continuep:
+ wsman_session_close(sid1);
+ }
+
+ wsman_session_close(sid);
+
+ printf("******** Closed session id %d ********\n\n", sid);
+
+ return 1;
+}