net.append(XenUtil.WC_FIELD_SEPARATOR);
final String clientProvidedMAC = nic.getMAC();
if (clientProvidedMAC != null
&& clientProvidedMAC.trim().length() > 0) {
throw new CreationException("no security policy in place for " +
"client MAC specification, this is disabled, resubmit " +
"without specific MAC requirement");
}
final String method = nic.getAcquisitionMethod();
if (method == null) {
throw new CreationException("no network method specification");
}
if (method.equals(NIC.ACQUISITION_AcceptAndConfigure)
|| method.equals(NIC.ACQUISITION_Advisory)) {
// todo: verify IP syntax here to identify a problem earlier
// (workspace_control will validate)
// (e.g., xml constraints don't check for >255 )
// TODO: move to authorization check section
if (!staticIPAllowed) {
throw new ResourceRequestDeniedException("request for " +
"non-allocate networking method is denied");
}
if (nic.getIpAddress() == null
|| nic.getBroadcast() == null
|| nic.getNetmask() == null) {
final String err = "acquisition method '" + method + "' " +
"requires at least IP, broadcast, and netmask settings";
throw new CreationException(err);
}
final String newMac = this.networkAdapter.newMAC();
if (newMac == null) {
net.append("ANY");
} else {
net.append(newMac);
}
net.append(XenUtil.WC_FIELD_SEPARATOR);
//only handling bridged
net.append("Bridged");
net.append(XenUtil.WC_FIELD_SEPARATOR);
net.append(method);
net.append(XenUtil.WC_FIELD_SEPARATOR);
// broadcast, gateway, and netmask can be null
net.append(nic.getIpAddress()).
append(XenUtil.WC_FIELD_SEPARATOR).
append(nic.getGateway()).
append(XenUtil.WC_FIELD_SEPARATOR).
append(nic.getBroadcast()).
append(XenUtil.WC_FIELD_SEPARATOR).
append(nic.getNetmask()).
append(XenUtil.WC_FIELD_SEPARATOR).
append("null").
append(XenUtil.WC_FIELD_SEPARATOR).
append("null").
append(XenUtil.WC_FIELD_SEPARATOR).
append("null").
append(XenUtil.WC_FIELD_SEPARATOR).
append("null").
append(XenUtil.WC_FIELD_SEPARATOR).
append("null").
append(XenUtil.WC_FIELD_SEPARATOR).
append("null");
} else if (method.equals(NIC.ACQUISITION_AllocateAndConfigure)) {
//todo: once default association is configurable, there
// will also be an option to disallow defaults.
// association being null means this
//if (association == null) {
// throw errorBind("noAllocate");
//}
if (nic.getIpAddress() != null ||
nic.getHostname() != null ||
nic.getBroadcast() != null ||
nic.getGateway() != null ||
nic.getNetmask() != null ||
nic.getNetwork() != null) {
final String err = "no specific NIC network settings should " +
"be specified for acquisition method '" + method + "'";
throw new CreationException(err);
}
int vmid = -1; // for logging
if (vm != null) {
final Integer integer = vm.getID();
if (integer != null) {
vmid = integer.intValue();
}
}
final Object[] entryAndDns =
this.networkAdapter.getNextEntry(association, vmid);
if (entryAndDns == null || entryAndDns[0] == null) {
// can't happen here, exception already thrown, but this is here
// for clarity (and code analysis tools)
final String err = "network '" + association
+ "' is not currently available";
logger.error(err);
throw new ResourceRequestDeniedException(err);
}
final AssociationEntry entry = (AssociationEntry) entryAndDns[0];
final String assignedMAC = entry.getMac();
if (assignedMAC == null) {
net.append("ANY");
} else {
net.append(assignedMAC);
}
net.append(XenUtil.WC_FIELD_SEPARATOR);
//only handling bridged
net.append("Bridged");
net.append(XenUtil.WC_FIELD_SEPARATOR);
net.append(method);
net.append(XenUtil.WC_FIELD_SEPARATOR);
net.append(entry.getIpAddress()).
append(XenUtil.WC_FIELD_SEPARATOR).
append(entry.getGateway()).
append(XenUtil.WC_FIELD_SEPARATOR).
append(entry.getBroadcast()).
append(XenUtil.WC_FIELD_SEPARATOR).
append(entry.getSubnetMask()).
append(XenUtil.WC_FIELD_SEPARATOR).
append(entryAndDns[1]).
append(XenUtil.WC_FIELD_SEPARATOR).
append(entry.getHostname()).
append(XenUtil.WC_FIELD_SEPARATOR);
// cert paths, old implementation
net.append("null").
append(XenUtil.WC_FIELD_SEPARATOR).
append("null").
append(XenUtil.WC_FIELD_SEPARATOR).
append("null").
append(XenUtil.WC_FIELD_SEPARATOR).
append("null");
} else {
// todo: or just leave it up to the implementation?
throw new CreationException("network method '" + method +
"' is not supported");
}
return net;
}