Ejemplo n.º 1
0
int ovCreate (char *sessionID, char *argument[])
{
    char urlString[256];
    
    char *oneViewAddress = argument[1]; // IP Address of HP OneView
    char *createType = argument[3]; // Type of information to create
    char *httpData;
    json_t *root;
    
    if (strstr(createType, "SERVER-PROFILES")) {
        createURL(urlString, oneViewAddress, "server-profiles");

        // This will just create a simple empty profile and apply it to an enclosure group
        root = json_pack("{s:s, s:s, s:s, s:s}","type", "ServerProfileV4", "name", argument[4], "serverHardwareTypeUri", argument[5], "enclosureGroupUri", argument[6]);
        char *json_text = json_dumps(root, JSON_ENSURE_ASCII);

        httpData = postRequestWithUrlAndDataAndHeader(urlString, json_text, sessionID);
        
        if(!httpData)
            return 1;
        
        free(json_text);

    } else if (strstr(argument[3], "SERVER-HARDWARE-TYPES")) {
        createURL(urlString, oneViewAddress, "server-hardware-types");

    } else if (strstr(argument[3], "ENCLOSURE-GROUPS")) {
        createURL(urlString, oneViewAddress, "enclosure-groups");

        // Comprehensive json needs creating for the Enlcosure Group type, Including details for all eight interconnect Bays
        root = json_pack("{s:s, s:s, s:s, s:[{s:i, s:s}, {s:i, s:s}     \
                                             {s:i, s:s}, {s:i, s:s},    \
Ejemplo n.º 2
0
int ovCopy (char *sessionID, char *argument[])
{
    
    char urlString[256]; // Used to hold a full URL
    char path[256]; // Used to hold path to a second session file

        // Check Arguments before continuing
        if (!sessionID) {
            return 1;
        }

    
    char *oneViewAddress = argument[1]; // IP Address of HP OneView
    char *copyType = argument[3]; // Type of information to show
    // char *queryType = argument[4]; // Type of Query to show
    char *httpData; // Contains all fo the data returned from a http request
    json_t *root; // Contains all of the json data once processed by jansson
    json_error_t error; // Used as a passback for error data during json processing
    
    if (strstr(copyType, "NETWORKS")) {
        createURL(urlString, oneViewAddress, "ethernet-networks");

        
        // Call to HP OneView API
        httpData = getRequestWithUrlAndHeader(urlString, sessionID);
        
        if(!httpData)
            return 1;
        
        root = json_loads(httpData, 0, &error);
        
        json_t *memberArray = json_object_get(root, "members");
        if (json_array_size(memberArray) != 0) {
            size_t index;
            json_t *network = NULL;
            //char *json_text;
            json_array_foreach(memberArray, index, network) {
                const char *uri = json_string_value(json_object_get(network, "uri"));
                if (uri != NULL) {
                    if (strstr(uri, argument[4])) {
                        // Remove bits
                        //json_object_del(network, "uri");
                        json_object_del(network, "eTag");
                        json_object_del(network, "modified");
                        json_object_del(network, "created");
                        json_object_del(network, "connectionTemplateUri");
                        createURL(urlString, argument[5], "ethernet-networks");
                        sprintf(path, "/.%s_ov",argument[5]);
                        
                        sessionID = readSessionIDforHost(path);
                        httpData = postRequestWithUrlAndDataAndHeader(urlString, json_dumps(network, JSON_ENSURE_ASCII), sessionID);
                        
                        if(!httpData)
                            return 1;
                        
                    }
                }
            }
        }
Ejemplo n.º 3
0
int main (int argc, const char * argv[]) {
    static char *suffix = ".watermarked.pdf";
    static char *stampFileName = "confidential.pdf";
    const char *inputFileName = NULL;
    char *outputFileName = NULL;
    CFURLRef inURL = NULL, outURL = NULL, stampURL = NULL;
    int outputnamelength;
    
    if(argc != 2){
		usage(argv[0]);
        return 1;
    }

    inputFileName = argv[1];
    outputnamelength = strlen(inputFileName) + strlen(suffix) + 1;
    outputFileName = (char *)malloc(outputnamelength);
    strncpy(outputFileName, inputFileName, outputnamelength);
    strncat(outputFileName, suffix, outputnamelength);
    
    inURL = createURL(inputFileName);
    if(!inURL){
		fprintf(stderr, "Couldn't create URL for input file!\n");
		return 1;
    }
    
    outURL = createURL(outputFileName);
    if(!outURL){
		CFRelease(inURL);
		fprintf(stderr, "Couldn't create URL for output file!\n");
		return 1;
    }

    stampURL = createURL(stampFileName);
    if(!stampURL){
		CFRelease(inURL);
		CFRelease(outURL);
		fprintf(stderr, "Couldn't create URL for stamping file!\n");
		return 1;
    }
    
    createStampedFileWithFile(inURL, stampURL, outURL);
    
    CFRelease(stampURL);
    CFRelease(outURL);
    CFRelease(inURL);
    return 0;
}
Ejemplo n.º 4
0
//remember free response
void sendCmd(char* method, char* object, int lampId, char* attr, char* msgBody, int port, char* ip) {
	char* url = createURL(object, lampId, attr);
	char* request = createRequestStr(method, url, msgBody);
	char* response = sendTcpRequest(request, port, ip);
	free(url);
	free(request);
	free(response);
}
Ejemplo n.º 5
0
/*
Address	http://<bridge ip address>/api/<username>/lights/<lampId>
Body
Method	GET
*/
int getLightState(int lampId) {
	char* url = createURL("/lights/", lampId, "");
	char* request = createRequestStr("GET", url, NULL);
	free(url);

	char* response = sendTcpRequest(request, 80, LAMP_BRIDGE_IP);
	free(request);
	free(response);
	return 1;
}
Ejemplo n.º 6
0
/*
Address	http://<bridge ip address>/api/<username>/lights/<lampId>/state
Body	<json>
Method	PUT
*/
int setLightState(int lampId, char* newState) {
	if(newState == NULL)
		return 0;
	if(strlen(newState) <= 0) {
		printf("need new state json description! \n");
		return 0;
	}

	char* url = createURL("/lights/", lampId, "/state");
	char* request = createRequestStr("PUT", url, newState);
	free(url);

	char* response = sendTcpRequest(request, 80, LAMP_BRIDGE_IP);

	free(request);
	//can also analyse response here
	free(response);
	return 1;
}