Permalink
Browse files

implemented describeNetworks

  • Loading branch information...
1 parent c55fed9 commit f7d0b095a353560156ab56f041c29eb6e524e66f root committed Aug 4, 2009
Showing with 183 additions and 29 deletions.
  1. +18 −0 cluster/cc-client-marshal-adb.c
  2. +8 −3 cluster/handlers.c
  3. +1 −1 cluster/handlers.h
  4. +39 −3 cluster/server-marshal.c
  5. +46 −20 net/vnetwork.c
  6. +1 −1 tools/eucalyptus-cc.in
  7. +56 −0 util/misc.c
  8. +2 −0 util/misc.h
  9. +12 −1 wsdl/eucalyptus_cc.wsdl
@@ -571,6 +571,24 @@ int cc_describeNetworks(char **ccs, int ccsLen, axutil_env_t *env, axis2_stub_t
}
snrt = adb_DescribeNetworksResponse_get_DescribeNetworksResponse(output, env);
printf("describenetworks returned status %d\n", adb_describeNetworksResponseType_get_return(snrt, env));
+
+ printf("mode: %d addrspernet: %d\n", adb_describeNetworksResponseType_get_mode(snrt, env), adb_describeNetworksResponseType_get_addrsPerNet(snrt, env));
+ {
+ int i, numnets, numaddrs, j;
+ numnets = adb_describeNetworksResponseType_sizeof_activeNetworks(snrt, env);
+ printf("found %d active nets\n", numnets);
+ for (i=0; i<numnets; i++) {
+ adb_networkType_t *nt;
+ nt = adb_describeNetworksResponseType_get_activeNetworks_at(snrt, env, i);
+ printf("\tvlan: %d netName: %s userName: %s\n", adb_networkType_get_vlan(nt, env), adb_networkType_get_netName(nt, env), adb_networkType_get_userName(nt, env));
+ numaddrs = adb_networkType_sizeof_activeAddrs(nt, env);
+ printf("\tnumber of active addrs: %d - ", numaddrs);
+ for (j=0; j<numaddrs; j++) {
+ printf("%d ", adb_networkType_get_activeAddrs_at(nt, env, j));
+ }
+ printf("\n");
+ }
+ }
return(0);
}
View
@@ -437,8 +437,8 @@ int doStopNetwork(ncMetadata *ccMeta, char *netName, int vlan) {
return(ret);
}
-int doDescribeNetworks(ncMetadata *ccMeta, char **ccs, int ccsLen) {
- int rc;
+int doDescribeNetworks(ncMetadata *ccMeta, char **ccs, int ccsLen, vnetConfig *outvnetConfig) {
+ int rc, i, j;
rc = initialize();
if (rc) {
@@ -448,9 +448,13 @@ int doDescribeNetworks(ncMetadata *ccMeta, char **ccs, int ccsLen) {
sem_wait(vnetConfigLock);
rc = vnetSetCCS(vnetconfig, ccs, ccsLen);
rc = vnetSetupTunnels(vnetconfig);
+
+ memcpy(outvnetConfig, vnetconfig, sizeof(vnetConfig));
+
sem_post(vnetConfigLock);
logprintfl(EUCADEBUG, "DescribeNetworks(): done\n");
+ shawn();
return(0);
}
@@ -756,7 +760,7 @@ int doDescribeInstances(ncMetadata *ccMeta, char **instIds, int instIdsLen, ccIn
ncInstance **ncOutInsts=NULL;
ncStub *ncs;
-
+
op_start = time(NULL);
op_timer = OP_TIMEOUT;
@@ -2073,6 +2077,7 @@ int init_config(void) {
pubInterface = strdup(tmpstr);
privInterface = strdup(tmpstr);
}
+
if (tmpstr) free(tmpstr);
if (!strcmp(pubmode, "STATIC")) {
View
@@ -101,7 +101,7 @@ int doDetachVolume(ncMetadata *ccMeta, char *volumeId, char *instanceId, char *r
int doAssignAddress(ncMetadata *ccMeta, char *src, char *dst);
int doUnassignAddress(ncMetadata *ccMeta, char *src, char *dst);
int doDescribePublicAddresses(ncMetadata *ccMeta, publicip **outAddresses, int *outAddressesLen);
-int doDescribeNetworks(ncMetadata *ccMeta, char **ccs, int ccsLen);
+int doDescribeNetworks(ncMetadata *ccMeta, char **ccs, int ccsLen, vnetConfig *outvnetConfig);
int doDescribeInstances(ncMetadata *meta, char **instIds, int instIdsLen, ccInstance **outInsts, int *outInstsLen);
int doRunInstances(ncMetadata *ccMeta, char *amiId, char *kernelId, char *ramdiskId, char *amiURL, char *kernelURL, char *ramdiskURL, char **instIds, int instIdsLen, char **netNames, int netNamesLen, char **macAddrs, int macAddrsLen, int minCount, int maxCount, char *ownerId, char *reservationId, virtualMachine *ccvm, char *keyName, int vlan, char *userData, char *launchIndex, char *targetNode, ccInstance **outInsts, int *outInstsLen);
View
@@ -6,6 +6,7 @@
#include <server-marshal.h>
#include <handlers.h>
#include <misc.h>
+#include <vnetwork.h>
#define DONOTHING 0
#define EVENTLOG 0
@@ -164,16 +165,19 @@ adb_DescribeNetworksResponse_t *DescribeNetworksMarshal(adb_DescribeNetworks_t *
//input vars
adb_describeNetworksType_t *snt=NULL;
-
+
// working vars
- int rc, i;
+ int rc, i, j;
axis2_bool_t status=AXIS2_TRUE;
char statusMessage[256];
char **clusterControllers;
int clusterControllersLen=0;
ncMetadata ccMeta;
+ vnetConfig *outvnetConfig=NULL;
+ outvnetConfig = malloc(sizeof(vnetConfig));
+
snt = adb_DescribeNetworks_get_DescribeNetworks(describeNetworks, env);
ccMeta.correlationId = adb_describeNetworksType_get_correlationId(snt, env);
ccMeta.userId = adb_describeNetworksType_get_userId(snt, env);
@@ -187,11 +191,41 @@ adb_DescribeNetworksResponse_t *DescribeNetworksMarshal(adb_DescribeNetworks_t *
snrt = adb_describeNetworksResponseType_create(env);
status = AXIS2_TRUE;
if (!DONOTHING) {
- rc = doDescribeNetworks(&ccMeta, clusterControllers, clusterControllersLen);
+ rc = doDescribeNetworks(&ccMeta, clusterControllers, clusterControllersLen, outvnetConfig);
if (rc) {
logprintf("ERROR: doDescribeNetworks() returned fail %d\n", rc);
status = AXIS2_FALSE;
snprintf(statusMessage, 255, "ERROR");
+ } else {
+
+ if (!strcmp(outvnetConfig->mode, "MANAGED") || !strcmp(outvnetConfig->mode, "MANAGED-NOVLAN")) {
+ adb_describeNetworksResponseType_set_mode(snrt, env, 1);
+ } else {
+ adb_describeNetworksResponseType_set_mode(snrt, env, 0);
+ }
+ adb_describeNetworksResponseType_set_addrsPerNet(snrt, env, outvnetConfig->numaddrs);
+
+ for (i=2; i<NUMBER_OF_VLANS; i++) {
+ if (outvnetConfig->networks[i].active) {
+ adb_networkType_t *nt=NULL;
+ nt = adb_networkType_create(env);
+ adb_networkType_set_vlan(nt, env, i);
+ adb_networkType_set_netName(nt, env, outvnetConfig->users[i].netName);
+ adb_networkType_set_userName(nt, env, outvnetConfig->users[i].userName);
+ logprintfl(EUCADEBUG, "ACTIVE VLAN: %d\n", i);
+ logprintfl(EUCADEBUG, "NETNAME: %s USERNAME: %s\n", outvnetConfig->users[i].netName, outvnetConfig->users[i].userName);
+ for (j=0; j<NUMBER_OF_HOSTS_PER_VLAN; j++) {
+ if (outvnetConfig->networks[i].addrs[j].active) {
+ adb_networkType_add_activeAddrs(nt, env, j);
+ logprintfl(EUCADEBUG, "\tACTIVE ADDR: %s\n", hex2dot(outvnetConfig->networks[i].addrs[j].ip));
+ }
+ }
+ adb_describeNetworksResponseType_add_activeNetworks(snrt, env, nt);
+ }
+ }
+
+ status = AXIS2_TRUE;
+ // snprintf(statusMessage, 255, "SUCCESS");
}
}
if (clusterControllers) free(clusterControllers);
@@ -207,8 +241,10 @@ adb_DescribeNetworksResponse_t *DescribeNetworksMarshal(adb_DescribeNetworks_t *
ret = adb_DescribeNetworksResponse_create(env);
adb_DescribeNetworksResponse_set_DescribeNetworksResponse(ret, env, snrt);
+ if (outvnetConfig) free(outvnetConfig);
return(ret);
}
+
adb_DescribePublicAddressesResponse_t *DescribePublicAddressesMarshal(adb_DescribePublicAddresses_t *describePublicAddresses, const axutil_env_t *env) {
adb_describePublicAddressesType_t *dpa=NULL;
View
@@ -949,6 +949,9 @@ int vnetStartNetworkManaged(vnetConfig *vnetconfig, int vlan, char *userName, ch
// char *newip, *netmask;
vnetconfig->networks[vlan].active = 1;
+ vnetconfig->networks[vlan].addrs[0].active = 1;
+ vnetconfig->networks[vlan].addrs[1].active = 1;
+
rc = vnetSetVlan(vnetconfig, vlan, userName, netName);
rc = vnetCreateChain(vnetconfig, userName, netName);
@@ -1159,14 +1162,27 @@ int vnetSetupTunnels(vnetConfig *vnetconfig) {
}
int vnetSetupTunnelsVTUN(vnetConfig *vnetconfig) {
- int i, done, rc;
- char cmd[1024], tundev[32], *remoteIp=NULL;
+ int i, done, rc, dpid;
+ char cmd[1024], tundev[32], *remoteIp=NULL, pidfile[1024];
- snprintf(cmd, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap vtund -s -f %s/etc/eucalyptus/vtunall.conf", vnetconfig->eucahome, vnetconfig->eucahome);
- logprintfl(EUCADEBUG, "running cmd '%s'\n", cmd);
- rc = system(cmd);
- rc = rc>>8;
- logprintfl(EUCADEBUG, "done: %d\n", rc);
+ snprintf(pidfile, 1024, "%s/var/run/eucalyptus/vtund-server.pid", vnetconfig->eucahome);
+ rc = check_file(pidfile);
+ if (rc) {
+ // pidfile does not exist, start vtund server
+ snprintf(cmd, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap vtund -s -n -f %s/etc/eucalyptus/vtunall.conf", vnetconfig->eucahome, vnetconfig->eucahome);
+ logprintfl(EUCADEBUG, "running cmd '%s'\n", cmd);
+ rc = daemonrun(cmd, &dpid);
+ logprintfl(EUCADEBUG, "done: %d\n", rc);
+ if (!rc && dpid >= 0) {
+ char pidstr[32];
+ snprintf(pidstr, 32, "%d", dpid);
+ // write pid
+ rc = write2file(pidfile, pidstr);
+ if (rc) {
+ logprintfl(EUCAERROR, "cannot write pid '%s' to file '%s'\n", pidstr, pidfile);
+ }
+ }
+ }
done=0;
for (i=0; i<NUMBER_OF_CCS && !done; i++) {
@@ -1179,19 +1195,28 @@ int vnetSetupTunnelsVTUN(vnetConfig *vnetconfig) {
snprintf(tundev, 32, "tap-%d-%d", vnetconfig->localIpId, i);
rc = check_device(tundev);
if (rc && (vnetconfig->ccsTunnelStart[i] == 0 || (time(NULL) - vnetconfig->ccsTunnelStart[i]) > 120)) {
-
- snprintf(cmd, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap vtund -f %s/etc/eucalyptus/vtunall.conf -p tun-%d-%d %s", vnetconfig->eucahome, vnetconfig->eucahome, vnetconfig->localIpId, i, remoteIp);
- logprintfl(EUCADEBUG, "running cmd '%s'\n", cmd);
- rc = system(cmd);
- rc = rc>>8;
- logprintfl(EUCADEBUG, "done: %d\n", rc);
-
- logprintfl(EUCADEBUG, "setting tunnel start time (%d): %d/%d\n", i, vnetconfig->ccsTunnelStart[i], time(NULL));
- vnetconfig->ccsTunnelStart[i] = time(NULL);
-
- if (remoteIp) free(remoteIp);
+ snprintf(pidfile, 1024, "%s/var/run/eucalyptus/vtund-client-%d-%d.pid", vnetconfig->eucahome, vnetconfig->localIpId, i);
+ rc = check_file(pidfile);
+ if (rc) {
+ snprintf(cmd, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap vtund -n -f %s/etc/eucalyptus/vtunall.conf -p tun-%d-%d %s", vnetconfig->eucahome, vnetconfig->eucahome, vnetconfig->localIpId, i, remoteIp);
+ logprintfl(EUCADEBUG, "running cmd '%s'\n", cmd);
+ rc = daemonrun(cmd, &dpid);
+ logprintfl(EUCADEBUG, "done: %d\n", rc);
+ if (!rc && dpid >= 0) {
+ char pidstr[32];
+ snprintf(pidstr, 32, "%d", dpid);
+ // write pid
+ rc = write2file(pidfile, pidstr);
+ if (rc) {
+ logprintfl(EUCAERROR, "cannot write pid '%s' to file '%s'\n", pidstr, pidfile);
+ }
+ }
+ logprintfl(EUCADEBUG, "setting tunnel start time (%d): %d/%d\n", i, vnetconfig->ccsTunnelStart[i], time(NULL));
+ vnetconfig->ccsTunnelStart[i] = time(NULL);
+ }
}
}
+ if (remoteIp) free(remoteIp);
}
}
return(0);
@@ -1617,12 +1642,12 @@ int ip2mac(vnetConfig *vnetconfig, char *ip, char **mac) {
snprintf(ipspace, 25, "%s ", ip);
while(fgets(rbuf, 256, FH) != NULL) {
- logprintfl(EUCADEBUG, "'%s' '%s' '%s'\n", rbuf, ip, strstr(rbuf, ip));
+ // logprintfl(EUCADEBUG, "'%s' '%s' '%s'\n", rbuf, ip, strstr(rbuf, ip));
if (strstr(rbuf, ipspace)) {
int count=0;
tok = strtok(rbuf, " ");
while(tok && count < 4) {
- logprintfl(EUCADEBUG, "COUNT: %d TOK: %s\n", count, tok);
+ // logprintfl(EUCADEBUG, "COUNT: %d TOK: %s\n", count, tok);
count++;
if (count < 4) {
tok = strtok(NULL, " ");
@@ -1768,3 +1793,4 @@ int vnetLoadIPTables(vnetConfig *vnetconfig) {
}
return(WEXITSTATUS(rc));
}
+
View
@@ -140,7 +140,7 @@ do_stop() {
fi
# now kill the services
- pidfiles="$EUCALYPTUS/var/run/eucalyptus/net/euca-dhcp.pid $EUCALYPTUS/var/run/eucalyptus/eucalyptus-cc.pid"
+ pidfiles="$EUCALYPTUS/var/run/eucalyptus/net/euca-dhcp.pid $EUCALYPTUS/var/run/eucalyptus/eucalyptus-cc.pid `ls -1 $EUCALYPTUS/var/run/eucalyptus/vtund*.pid 2>/dev/null`"
for pidfile in $pidfiles ; do
if [ -s $pidfile ]; then
pid=`cat $pidfile 2> /dev/null`
View
@@ -655,6 +655,49 @@ char * get_string_stats (const char * s)
#define BUFSIZE 1024
+/* daemonize and run 'cmd', returning pid of the daemonized process */
+int daemonrun(char *cmd, int *dpid) {
+ int pid, sid, i;
+ char **argv=NULL;
+
+ *dpid = -1;
+ pid = fork();
+ if (pid < 0) {
+ return(1);
+ }
+
+ if (!pid) {
+ char *tok, *ptr;
+ int idx;
+
+ // become parent of session
+ sid = setsid();
+
+ // construct argv
+ idx=0;
+ argv = realloc(NULL, sizeof(char *));
+ tok = strtok_r(cmd, " ", &ptr);
+ while(tok) {
+ argv[idx] = strdup(tok);
+ idx++;
+ tok = strtok_r(NULL, " ", &ptr);
+ argv = realloc(argv, sizeof(char *) * (idx+1));
+ }
+ argv[idx] = NULL;
+
+ // close all fds
+ for (i=0; i<sysconf(_SC_OPEN_MAX); i++) {
+ close(i);
+ }
+
+ // run
+ exit(execvp(*argv, argv));
+ }
+
+ *dpid = pid;
+ return(0);
+}
+
/* given printf-style arguments, run the resulting string in the shell */
int vrun (const char * fmt, ...)
{
@@ -803,6 +846,19 @@ long long dir_size (const char * path)
return size;
}
+int write2file(const char *path, char *str) {
+ FILE *FH=NULL;
+
+ FH = fopen(path, "w");
+ if (FH) {
+ fprintf(FH, "%s", str);
+ fclose(FH);
+ } else {
+ return(1);
+ }
+ return(0);
+}
+
/* read file 'path' into a new string */
char * file2str (const char * path)
{
View
@@ -92,6 +92,7 @@ int param_check(char *func, ...);
int hash_code (const char * s);
char * get_string_stats (const char * s);
+int daemonrun(char *cmd, int *dpid);
int run (const char * arg1, ...);
int vrun (const char * fmt, ...);
int cat (const char * file_name);
@@ -100,6 +101,7 @@ int touch (const char * path);
int diff (const char * path1, const char * path2);
long long dir_size (const char * path);
char * file2str (const char * path); /* read file 'path' into a new string */
+int write2file(const char *path, char *str);
long long str2longlong (const char * str, const char * begin, const char * end); /* extract integer from str bound by 'begin' and 'end' */
pid_t timewait(pid_t pid, int *status, int timeout);
View
@@ -320,12 +320,23 @@
<xs:complexContent>
<xs:extension base="tns:eucalyptusMessage">
<xs:sequence>
- <xs:element minOccurs="0" maxOccurs="1" name="mode" type="xs:string"/>
+ <xs:element minOccurs="0" maxOccurs="1" name="mode" type="xs:int"/>
+ <xs:element minOccurs="0" maxOccurs="1" name="addrsPerNet" type="xs:int"/>
+ <xs:element minOccurs="0" maxOccurs="unbounded" name="activeNetworks" type="tns:networkType"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
+ <xs:complexType name="networkType">
+ <xs:sequence>
+ <xs:element minOccurs="1" maxOccurs="1" name="vlan" type="xs:int"/>
+ <xs:element minOccurs="1" maxOccurs="1" name="netName" type="xs:string"/>
+ <xs:element minOccurs="1" maxOccurs="1" name="userName" type="xs:string"/>
+ <xs:element minOccurs="0" maxOccurs="unbounded" name="activeAddrs" type="xs:int"/>
+ </xs:sequence>
+ </xs:complexType>
+
<xs:complexType name="describePublicAddressesType">
<xs:complexContent>
<xs:extension base="tns:eucalyptusMessage">

0 comments on commit f7d0b09

Please sign in to comment.