Skip to content

Commit

Permalink
HAize SYSTEM and STATIC mode(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Mar 5, 2011
1 parent d4da676 commit a9c2c02
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 48 deletions.
2 changes: 1 addition & 1 deletion cluster/handlers-state.c
Expand Up @@ -350,7 +350,7 @@ int instNetParamsSet(ccInstance *inst, void *in) {
snprintf(vnetconfig->users[inst->ccnet.vlan].userName, 48, "%s", inst->accountId);
}
}
}
}

if (!ret) {
// so far so good
Expand Down
66 changes: 31 additions & 35 deletions cluster/handlers.c
Expand Up @@ -954,7 +954,7 @@ int doDescribePublicAddresses(ncMetadata *ccMeta, publicip **outAddresses, int *
} else {
*outAddresses = NULL;
*outAddressesLen = 0;
ret=2;
ret=0;
}

logprintfl(EUCADEBUG, "DescribePublicAddresses(): done. \n");
Expand Down Expand Up @@ -3721,33 +3721,34 @@ int restoreNetworkState() {
ret = 1;
}

// restore iptables state, if internal iptables state exists
logprintfl(EUCADEBUG, "restoreNetworkState(): restarting iptables\n");
rc = vnetRestoreTablesFromMemory(vnetconfig);
if (rc) {
logprintfl(EUCAERROR, "restoreNetworkState(): cannot restore iptables state\n");
ret = 1;
}

// re-create all active networks (bridges, vlan<->bridge mappings)
logprintfl(EUCADEBUG, "restoreNetworkState(): restarting networks\n");
for (i=2; i<NUMBER_OF_VLANS; i++) {
if (vnetconfig->networks[i].active) {
char *brname=NULL;
logprintfl(EUCADEBUG, "restoreNetworkState(): found active network: %d\n", i);
rc = vnetStartNetwork(vnetconfig, i, NULL, vnetconfig->users[i].userName, vnetconfig->users[i].netName, &brname);
if (rc) {
logprintfl(EUCADEBUG, "restoreNetworkState(): failed to reactivate network: %d", i);
if (!strcmp(vnetconfig->mode, "MANAGED") || !strcmp(vnetconfig->mode, "MANAGED-NOVLAN")) {
// restore iptables state, if internal iptables state exists
logprintfl(EUCADEBUG, "restoreNetworkState(): restarting iptables\n");
rc = vnetRestoreTablesFromMemory(vnetconfig);
if (rc) {
logprintfl(EUCAERROR, "restoreNetworkState(): cannot restore iptables state\n");
ret = 1;
}

// re-create all active networks (bridges, vlan<->bridge mappings)
logprintfl(EUCADEBUG, "restoreNetworkState(): restarting networks\n");
for (i=2; i<NUMBER_OF_VLANS; i++) {
if (vnetconfig->networks[i].active) {
char *brname=NULL;
logprintfl(EUCADEBUG, "restoreNetworkState(): found active network: %d\n", i);
rc = vnetStartNetwork(vnetconfig, i, NULL, vnetconfig->users[i].userName, vnetconfig->users[i].netName, &brname);
if (rc) {
logprintfl(EUCADEBUG, "restoreNetworkState(): failed to reactivate network: %d", i);
}
if (brname) free(brname);
}
if (brname) free(brname);
}
}

// ret = vnetReassignAddress(vnetconfig, uuid, src, dst);
rc = map_instanceCache(validCmp, NULL, instNetReassignAddrs, NULL);
if (rc) {
logprintfl(EUCAERROR, "restoreNetworkState(): could not (re)assign public/private IP mappings\n");
ret = 1;

rc = map_instanceCache(validCmp, NULL, instNetReassignAddrs, NULL);
if (rc) {
logprintfl(EUCAERROR, "restoreNetworkState(): could not (re)assign public/private IP mappings\n");
ret = 1;
}
}

// get DHCPD back up and running
Expand All @@ -3760,14 +3761,6 @@ int restoreNetworkState() {

sem_mypost(VNET);

/*
// get current rules from CLC
rc = reconfigureNetworkFromCLC();
if (rc) {
logprintfl(EUCAWARN, "restoreNetworkState(): cannot get network ground truth from CLC\n");
}
*/

logprintfl(EUCADEBUG, "restoreNetworkState(): done restoring network state\n");

return(ret);
Expand All @@ -3779,6 +3772,10 @@ int reconfigureNetworkFromCLC() {
int fd=0, i=0, rc=0, ret=0, usernetlen=0;
FILE *FH=NULL;

if (strcmp(vnetconfig->mode, "MANAGED") && strcmp(vnetconfig->mode, "MANAGED-NOVLAN")) {
return(0);
}

// get the latest cloud controller IP address
if (vnetconfig->cloudIp) {
cloudIp = hex2dot(vnetconfig->cloudIp);
Expand All @@ -3790,7 +3787,6 @@ int reconfigureNetworkFromCLC() {
}
}


// create and populate network state files
snprintf(clcnetfile, MAX_PATH, "/tmp/euca-clcnet-XXXXXX");
snprintf(chainmapfile, MAX_PATH, "/tmp/euca-chainmap-XXXXXX");
Expand Down
44 changes: 32 additions & 12 deletions net/vnetwork.c
Expand Up @@ -1084,32 +1084,52 @@ int vnetGetAllVlans(vnetConfig *vnetconfig, char ***outusers, char ***outnets, i
}

int vnetGenerateNetworkParams(vnetConfig *vnetconfig, char *instId, int vlan, int nidx, char *outmac, char *outpubip, char *outprivip) {
int rc, ret=0, networkIdx;
int rc, ret=0, networkIdx, found, i;
uint32_t inip;

if (!instId || !outmac || !outpubip || !outprivip) {
logprintfl(EUCAERROR, "vnetGenerateNetworkParams(): bad input params\n");
return(1);
}

rc = instId2mac(instId, outmac);
if (rc) {
logprintfl(EUCAERROR, "vnetGenerateNetworkParams(): unable to convert instanceId (%s) to mac address\n", instId);
return(1);
}

ret = 1;
// define/get next mac and allocate IP
if (!strcmp(vnetconfig->mode, "STATIC") || !strcmp(vnetconfig->mode, "STATIC-DYNMAC")) {
// search for existing entry
inip = dot2hex(outprivip);
found=0;
for (i=2; i<vnetconfig->numaddrs-2 && !found; i++) {
logprintfl(EUCADEBUG, "HELLO: %d %s %s %s %d %d\n", i, outmac, hex2dot(inip), hex2dot(vnetconfig->networks[0].addrs[i].ip), machexcmp(outmac, vnetconfig->networks[0].addrs[i].mac), (vnetconfig->networks[0].addrs[i].ip == inip));
if (!machexcmp(outmac, vnetconfig->networks[0].addrs[i].mac) && (vnetconfig->networks[0].addrs[i].ip == inip)) {
logprintfl(EUCADEBUG, "WOOT: %d %s %s %s %d %d\n", i, outmac, hex2dot(inip), hex2dot(vnetconfig->networks[0].addrs[i].ip), machexcmp(outmac, vnetconfig->networks[0].addrs[i].mac), (vnetconfig->networks[0].addrs[i].ip == inip));
vnetconfig->networks[0].addrs[i].active = 1;
found++;
ret=0;
}
}
// get the next valid mac/ip pairing for this vlan
outmac[0] = '\0';
rc = vnetGetNextHost(vnetconfig, outmac, outprivip, 0, -1);
if (!rc) {
snprintf(outpubip, strlen(outprivip)+1, "%s", outprivip);
ret = 0;
if (!found) {
outmac[0] = '\0';
rc = vnetGetNextHost(vnetconfig, outmac, outprivip, 0, -1);
if (!rc) {
snprintf(outpubip, strlen(outprivip)+1, "%s", outprivip);
ret = 0;
}
}
} else if (!strcmp(vnetconfig->mode, "SYSTEM")) {
rc = instId2mac(instId, outmac);
if (rc) {
logprintfl(EUCAERROR, "vnetGenerateNetworkParams(): unable to convert instanceId (%s) to mac address\n", instId);
return(1);
}
ret = 0;
} else if (!strcmp(vnetconfig->mode, "MANAGED") || !strcmp(vnetconfig->mode, "MANAGED-NOVLAN")) {
rc = instId2mac(instId, outmac);
if (rc) {
logprintfl(EUCAERROR, "vnetGenerateNetworkParams(): unable to convert instanceId (%s) to mac address\n", instId);
return(1);
}

if (nidx == -1) {
networkIdx = -1;
} else {
Expand Down

0 comments on commit a9c2c02

Please sign in to comment.