/* ---------------------------------------------------------------------------*/ char * get_ec2_imgname(struct ec2_subscription* subptr, char *imgname,char * zone) { char srcdir[1024]; PyObject *pName=NULL, *pModule=NULL, *pDict=NULL, *pFunc=NULL,*result=NULL; PyThreadState* pythr=NULL; char * response; //python interface sprintf(srcdir,"%s/pyaccords/pysrc",PYPATH); pythr = Py_NewInterpreter(); python_path(srcdir); pName = PyString_FromString("ec2client"); if(pName == NULL) printf("erro: in ec2client.py no such file name\n"); else pModule = PyImport_Import(pName); if(pModule == NULL) printf("error: failed to load ec2client module\n"); else pDict = PyModule_GetDict(pModule); if(pDict == NULL) printf("error: failed to load dict name in ec2client module\n"); else pFunc = PyDict_GetItemString(pDict,"ec2_get_image"); if(pFunc == NULL) printf("error: failed to load ec2_get_image function in ec2client module\n"); else result=PyObject_CallFunction(pFunc,"ssss",subptr->accesskey,subptr->secretkey,imgname,zone); if (!result || PyErr_Occurred()) { PyErr_Print(); return (0); } response=allocate_string(PyString_AsString( result )); Py_DECREF(pModule); Py_DECREF(pName); Py_EndInterpreter(pythr); return response; }
/* ----------------------------------------------------------------- */ char * get_ec2_flavor(int memory, int cores, int speed, int storage, char * architecture) { char srcdir[1024]; PyObject *pName=NULL, *pModule=NULL, *pDict=NULL, *pFunc=NULL,*result=NULL; PyThreadState* pythr=NULL; char * response; //python interface sprintf(srcdir,"%s/pyaccords/pysrc",PYPATH); pythr = Py_NewInterpreter(); python_path(srcdir); pName = PyString_FromString("ec2client"); if(pName == NULL) printf("erro: in ec2client.py no such file name\n"); else pModule = PyImport_Import(pName); if(pModule == NULL) printf("error: failed to load ec2client module\n"); else pDict = PyModule_GetDict(pModule); if(pDict == NULL) printf("error: failed to load dict name in ec2client module\n"); else pFunc = PyDict_GetItemString(pDict,"ec2_get_flavor"); if(pFunc == NULL) printf("error: failed to load ec2_get_flavor function in ec2client module\n"); else result=PyObject_CallFunction(pFunc,"iiiis",memory,cores,speed,storage,architecture); if (!result || PyErr_Occurred()) { PyErr_Print(); return (0); } response=allocate_string(PyString_AsString( result )); Py_DECREF(pModule); Py_DECREF(pName); Py_EndInterpreter(pythr); return response; }
static EmacsString calcNewPythonPath(void) { EmacsString new_python_path("PYTHONPATH="); EmacsString python_path( get_config_env("PYTHONPATH") ); if( !python_path.isNull() ) { new_python_path.append( python_path ); new_python_path.append( ';' ); } EmacsString emacs_path( EMACS_PATH ); emacs_path.append(';'); // simplify loop EmacsString part; int start_pos = 0; for(;;) { int index = emacs_path.index( ';', start_pos ); if( index < 0 ) break; part = emacs_path( start_pos, index ); start_pos = index+1; EmacsString new_part; expand_and_default( part, EmacsString::null, new_part ); new_python_path.append( new_part ); new_python_path.append( ';' ); } // remove trailing ';' new_python_path.remove( new_python_path.length()-1, 1 ); return new_python_path; }
private int intercloudGW_create(struct occi_category * optr, void * vptr, struct rest_request * rptr) { struct occi_kind_node * nptr; struct intercloudGW * pptr; char sendstr[1024]; char strtmp[1024]; char srcdir[1024]; char * response = NULL; char * token; listcc categoryAtr; PyObject *pName=NULL, *pModule=NULL, *pDict=NULL, *pFunc=NULL,*result=NULL; PyThreadState* pythr=NULL; if (!( nptr = vptr )) return(0); else if (!( pptr = nptr->contents )) return(0); if(!(pptr->name)) strcpy(sendstr," "); else if(pptr->name[0]=='\0') strcpy(sendstr," "); else strcpy(sendstr,pptr->name); if(!(pptr->node)){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else if(pptr->node[0]=='\0'){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->node,','); if(!(pptr->account)){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else if(pptr->account[0]=='\0'){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->account,','); if(!(pptr->price)){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else if(pptr->price[0]=='\0'){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->price,','); if(!(pptr->state)){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else if(pptr->state[0]=='\0'){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->state,','); // python interface sprintf(srcdir,"%s/pyaccords/pysrc",PYPATH); pythr = Py_NewInterpreter(); python_path(srcdir); pName = PyString_FromString("intercloudGW"); if(pName == NULL) printf("erro: in intercloudGW no such file name\n"); else pModule = PyImport_Import(pName); if(pModule == NULL) printf("error: failed to load intercloudGW module\n"); else pDict = PyModule_GetDict(pModule); if(pDict == NULL) printf("error: failed to load dict name in intercloudGW module\n"); else pFunc = PyDict_GetItemString(pDict,"create"); if(pFunc == NULL) printf("error: failed to load create function in intercloudGW module\n"); else result=PyObject_CallFunction(pFunc,"s",sendstr); if(result) response=allocate_string(PyString_AsString( result )); Py_DECREF(pModule); Py_DECREF(pName); Py_EndInterpreter(pythr); resetListe(&categoryAtr); token= strtok(response,","); for(; token != NULL ;) { addBacke(&categoryAtr,token); token=strtok(NULL, ","); } elemm *pelem = categoryAtr.first; if(pelem){ pptr->name = pelem->value; pelem = pelem->next; } if(pelem){ pptr->node = pelem->value; pelem = pelem->next; } if(pelem){ pptr->account = pelem->value; pelem = pelem->next; } if(pelem){ pptr->price = pelem->value; pelem = pelem->next; } if(pelem){ pptr->state = pelem->value; } return 1; }
/* ----------------------------------------------------------------- */ int restart_ec2_instance( struct amazonEc2 * pptr ) { struct ec2_subscription * subptr = (struct ec2_subscription *) 0; int status = 0; char srcdir[1024]; char * response; char * token; char sendstr[1024]=" "; char strtmp[1024]=" "; listcc categoryAtr; PyObject *pName=NULL, *pModule=NULL, *pDict=NULL, *pFunc=NULL,*result=NULL; PyThreadState* pythr=NULL; /* ------------------------ */ /* prepare the subscription */ /* ------------------------ */ if (!( pptr )) return(118); else if (!(subptr = use_ec2_configuration( get_default_agent(),default_tls(),pptr->profile ))) return(118); if(!(strValid(pptr->id))) strcpy(sendstr," "); else strcpy(sendstr,pptr->id); if(!(strValid(pptr->name))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->name,','); if(!(strValid(pptr->flavor))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->flavor,','); if(!(strValid(pptr->image))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->image,','); if(!(strValid(pptr->original))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->original,','); if(!(strValid(pptr->profile))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->profile,','); if(!(strValid(pptr->node))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->node,','); if(!(strValid(pptr->price))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->price,','); if(!(strValid(pptr->account))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->account,','); if(!(strValid(pptr->number))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->number,','); if(!(strValid(pptr->rootpass))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->rootpass,','); if(!(strValid(pptr->reference))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->reference,','); if(!(strValid(pptr->network))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->network,','); if(!(strValid(pptr->access))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->access,','); if(!(strValid(pptr->accessip))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->accessip,','); if(!(strValid(pptr->keypair))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->keypair,','); if(!(strValid(pptr->placementgroup))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->placementgroup,','); if(!(strValid(pptr->publicaddr))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->publicaddr,','); if(!(strValid(pptr->privateaddr))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->privateaddr,','); if(!(strValid(pptr->firewall))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->firewall,','); if(!(strValid(pptr->group))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->group,','); if(!(strValid(pptr->zone))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->zone,','); if(!(strValid(pptr->hostname))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->hostname,','); if(!(strValid(pptr->workload))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->workload,','); if(!(strValid(pptr->agent))){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->agent,','); sprintf(strtmp,"%d",pptr->when); if(strValid(strcmp)) strConcat(sendstr,strtmp,','); else strConcat(sendstr," ",','); sprintf(strtmp,"%d",pptr->state); if(strValid(strtmp)) strConcat(sendstr,strtmp,','); else strConcat(sendstr," ",','); // python interface sprintf(srcdir,"%s/pyaccords/pysrc",PYPATH); pythr = Py_NewInterpreter(); python_path(srcdir); pName = PyString_FromString("amazonEc2Act"); if(pName == NULL) printf("erro: in amazonEc2Act.py no such file name\n"); else pModule = PyImport_Import(pName); if(pModule == NULL) printf("error: failed to load amazonEc2Act module\n"); else pDict = PyModule_GetDict(pModule); if(pDict == NULL) printf("error: failed to load dict name in amazonEc2Act module\n"); else pFunc = PyDict_GetItemString(pDict,"restart"); if(pFunc == NULL) printf("error: failed to load start function in amazonEc2Act module\n"); else result=PyObject_CallFunction(pFunc,"ssss",subptr->accesskey,subptr->secretkey,subptr->zone,sendstr); if (!result || PyErr_Occurred()) { PyErr_Print(); return (0); } response=allocate_string(PyString_AsString( result )); Py_DECREF(pModule); Py_DECREF(pName); Py_EndInterpreter(pythr); resetListe(&categoryAtr); token= strtok(response,","); for(; token != NULL ;) { addBacke(&categoryAtr,token); token=strtok(NULL, ","); } elemm *pelem = categoryAtr.first; if(pelem){ pptr->id = pelem->value; pelem = pelem->next; } if(pelem){ pptr->name = pelem->value; pelem = pelem->next; } if(pelem){ pptr->flavor = pelem->value; pelem = pelem->next; } if(pelem){ pptr->image = pelem->value; pelem = pelem->next; } if(pelem){ pptr->original = pelem->value; pelem = pelem->next; } if(pelem){ pptr->profile = pelem->value; pelem = pelem->next; } if(pelem){ pptr->node = pelem->value; pelem = pelem->next; } if(pelem){ pptr->price = pelem->value; pelem = pelem->next; } if(pelem){ pptr->account = pelem->value; pelem = pelem->next; } if(pelem){ pptr->number = pelem->value; pelem = pelem->next; } if(pelem){ pptr->rootpass = pelem->value; pelem = pelem->next; } if(pelem){ pptr->reference = pelem->value; pelem = pelem->next; } if(pelem){ pptr->network = pelem->value; pelem = pelem->next; } if(pelem){ pptr->access = pelem->value; pelem = pelem->next; } if(pelem){ pptr->accessip = pelem->value; pelem = pelem->next; } if(pelem){ pptr->keypair = pelem->value; pelem = pelem->next; } if(pelem){ pptr->placementgroup = pelem->value; pelem = pelem->next; } if(pelem){ pptr->publicaddr = pelem->value; pelem = pelem->next; } if(pelem){ pptr->privateaddr = pelem->value; pelem = pelem->next; } if(pelem){ pptr->firewall = pelem->value; pelem = pelem->next; } if(pelem){ pptr->group = pelem->value; pelem = pelem->next; } if(pelem){ pptr->zone = pelem->value; pelem = pelem->next; } if(pelem){ pptr->hostname = pelem->value; pelem = pelem->next; } if(pelem){ pptr->workload = pelem->value; pelem = pelem->next; } if(pelem){ pptr->agent = pelem->value; pelem = pelem->next; } if(pelem){ pptr->when = atoi(pelem->value); pelem = pelem->next; } if(pelem){ pptr->state = atoi(pelem->value); } return status; }
/*-------------------------------------------------------------------------------*/ struct rest_response * start_intercloudGW( struct occi_category * optr, struct rest_client * cptr, struct rest_request * rptr, struct rest_response * aptr, void * vptr ) { struct intercloudGW * pptr; char sendstr[1024]=" "; char strtmp[1024]=" "; int status; char message[1024]; char srcdir[1024]; char * response = NULL; char * token; FILE * exp_file; listcc restResponse; PyObject *pName=NULL, *pModule=NULL, *pDict=NULL, *pFunc=NULL,*result=NULL; PyThreadState* pythr=NULL; if (!( pptr = vptr )) return( rest_html_response( aptr, 404, "Invalid Action" ) ); else{ if(!(pptr->name))strcpy(sendstr," "); else if(pptr->name[0]=='\0') strcpy(sendstr," "); else strcpy(sendstr,pptr->name); if(!(pptr->node)){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else if(pptr->node[0]=='\0'){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->node,','); if(!(pptr->account)){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else if(pptr->account[0]=='\0'){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->account,','); if(!(pptr->price)){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else if(pptr->price[0]=='\0'){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->price,','); if(!(pptr->state)){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else if(pptr->state[0]=='\0'){ strcpy(strtmp," "); strConcat(sendstr,strtmp,','); } else strConcat(sendstr,pptr->state,','); // python interface sprintf(srcdir,"%s/pyaccords/pysrc",PYPATH); pythr = Py_NewInterpreter(); python_path(srcdir); pName = PyString_FromString("intercloudGWAct"); if(pName == NULL) printf("erro: in intercloudGWAct no such file name\n"); else pModule = PyImport_Import(pName); if(pModule == NULL) printf("error: failed to load intercloudGWAct module\n"); else pDict = PyModule_GetDict(pModule); if(pDict == NULL) printf("error: failed to load dict name in intercloudGW module\n"); else pFunc = PyDict_GetItemString(pDict,"start"); if(pFunc == NULL) printf("error: failed to load start function in intercloudGW module\n"); else result=PyObject_CallFunction(pFunc,"s",sendstr); if(result) response=allocate_string(PyString_AsString( result )); Py_DECREF(pModule); Py_DECREF(pName); Py_EndInterpreter(pythr); resetListe(&restResponse); token= strtok(response,","); for(; token != NULL ;) { addBacke(&restResponse,token); token=strtok(NULL, ","); } elemm *pelem = restResponse.first; if(pelem){ status = atoi(pelem->value); pelem = pelem->next; } if(pelem){ strcpy(message, pelem->value); pelem = pelem->next; } return( rest_html_response( aptr, status, message ) ); } }