use of org.apache.cloudstack.network.contrail.management.ContrailManager in project cloudstack by apache.
the class VirtualNetworkModel method setProperties.
/**
* Initialize the object properties based on the DB object.
* Common code between plugin calls and DBSync.
*/
public void setProperties(ModelController controller, Network network) {
ContrailManager manager = controller.getManager();
_name = manager.getCanonicalName(network);
_prefix = network.getCidr();
_gateway = network.getGateway();
// For non-cloudstack managed network, find the uuid at this stage.
if (!isDynamicNetwork()) {
try {
_uuid = manager.findVirtualNetworkId(network);
} catch (IOException ex) {
s_logger.warn("Unable to read virtual-network", ex);
}
}
_id = network.getId();
try {
_projectId = manager.getProjectId(network.getDomainId(), network.getAccountId());
} catch (IOException ex) {
s_logger.warn("project read", ex);
throw new CloudRuntimeException(ex);
}
_initialized = true;
}
use of org.apache.cloudstack.network.contrail.management.ContrailManager in project cloudstack by apache.
the class VirtualMachineModel method buildServiceInstance.
/**
* Link the virtual machine with the service instance when recovering state from database.
*
* @param controller
* @param serviceUuid
*/
private void buildServiceInstance(ModelController controller, String serviceUuid) {
ContrailManager manager = controller.getManager();
ApiConnector api = controller.getApiAccessor();
_serviceUuid = serviceUuid;
ServiceInstance siObj;
try {
siObj = (ServiceInstance) api.findById(ServiceInstance.class, serviceUuid);
} catch (IOException ex) {
s_logger.warn("service-instance read", ex);
throw new CloudRuntimeException("Unable to read service-instance object", ex);
}
ServiceInstanceModel siModel;
String fqn = StringUtils.join(siObj.getQualifiedName(), ':');
siModel = manager.getDatabase().lookupServiceInstance(fqn);
if (siModel == null) {
siModel = new ServiceInstanceModel(serviceUuid);
siModel.build(controller, siObj);
manager.getDatabase().getServiceInstances().add(siModel);
}
/*
* The code that was under the ELSE was never executed and due to that has been removed.
* Also, in the case siObj was null, it was going pass it as parameter to the build() method in the
* siModel object.
*/
_serviceModel = siModel;
}
use of org.apache.cloudstack.network.contrail.management.ContrailManager in project cloudstack by apache.
the class VirtualMachineModel method destroy.
@Override
public void destroy(ModelController controller) throws IOException {
delete(controller);
for (ModelObject successor : successors()) {
successor.destroy(controller);
}
clearSuccessors();
if (_serviceModel != null) {
_serviceModel.removeSuccessor(this);
_serviceModel.destroy(controller);
ContrailManager manager = controller.getManager();
manager.getDatabase().getServiceInstances().remove(_serviceModel);
_serviceModel = null;
}
}
use of org.apache.cloudstack.network.contrail.management.ContrailManager in project cloudstack by apache.
the class VirtualMachineModel method setServiceInstanceNics.
private void setServiceInstanceNics(ModelController controller, VMInstanceVO instance) throws IOException {
NicDao nicDao = controller.getNicDao();
ContrailManager manager = controller.getManager();
NetworkDao networkDao = controller.getNetworkDao();
List<NicVO> nics = nicDao.listByVmId(_instanceId);
for (NicVO nic : nics) {
String tag;
switch(nic.getDeviceId()) {
case 0:
tag = "management";
break;
case 1:
tag = "left";
break;
case 2:
tag = "right";
break;
default:
tag = null;
}
VMInterfaceModel vmiModel = getVMInterface(nic.getUuid());
if (vmiModel == null) {
vmiModel = new VMInterfaceModel(nic.getUuid());
vmiModel.addToVirtualMachine(this);
NetworkVO network = networkDao.findById(nic.getNetworkId());
VirtualNetworkModel vnModel = manager.getDatabase().lookupVirtualNetwork(network.getUuid(), manager.getCanonicalName(network), network.getTrafficType());
assert vnModel != null;
vmiModel.addToVirtualNetwork(vnModel);
}
vmiModel.setProperties(controller, instance, nic);
vmiModel.setServiceTag(tag);
}
}
use of org.apache.cloudstack.network.contrail.management.ContrailManager in project cloudstack by apache.
the class VirtualMachineModel method setProperties.
/**
* Initialize the object properties based on the DB object.
* Common code between plugin calls and DBSync.
*/
public void setProperties(ModelController controller, VMInstanceVO instance) {
ContrailManager manager = controller.getManager();
_instanceName = instance.getInstanceName();
_active = isActiveInstance(instance);
try {
_projectId = manager.getProjectId(instance.getDomainId(), instance.getAccountId());
} catch (IOException ex) {
s_logger.warn("project read", ex);
throw new CloudRuntimeException(ex);
}
_initialized = true;
}
Aggregations