Accessing a Remote Property in RAD in C

This example shows how to access a remote property.

Example 2-12 C Language – Accessing a RAD Remote Property

#include <rad/radclient.h>
#include <rad/radclient_basetypes.h>
#include <rad/client/1/zonemgr.h>

int
main(int argc, char **argv)
{
        rc_err_t status;
        rc_instance_t *zone_inst;
        char *name;
        zonemgr_Property_t **result;
        zonemgr_Result_t *error;
        int result_count;

        rc_conn_t *conn = rc_connect_unix(NULL, NULL);

        if (conn != NULL) {
                status = zonemgr_Zone__rad_lookup(conn, B_TRUE, &zone_inst,
1,
                    "name", "test-0");
                if (status == RCE_OK) {
                        zonemgr_Resource_t global = { .zr_type = "global"};
                        status =
zonemgr_Zone_getResourceProperties(zone_inst,
                            &global, NULL, 0, &result, &result_count, &error);
                        if (status == RCE_OK) {
                                for (int i = 0; i < result_count; i++){
                                        if (result[i]->zp_value != NULL &&
                                            result[i]->zp_value[0] != '\0') {
                                                printf("%s=%s\n",
                                                    result[i]->zp_name,
                                                    result[i]->zp_value);
                                        }
                                }
                                zonemgr_Property_array_free(result,
result_count);
                        }
                        rc_instance_rele(zone_inst);
                }
        }
}

In this example, you have accessed the list of global resource properties of the Zone and printed the name and value of every property that has a value.