use of com.cloud.agent.api.CreateBcfAttachmentCommand in project cloudstack by apache.
the class BigSwitchBcfElement method prepare.
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
if (!canHandle(network, Service.Connectivity)) {
return false;
}
bcfUtilsInit();
// get arguments for CreateBcfAttachmentCommand
// determine whether this is VPC network or stand-alone network
Vpc vpc = null;
if (network.getVpcId() != null) {
vpc = _vpcDao.acquireInLockTable(network.getVpcId());
}
String tenantId;
String tenantName;
if (vpc != null) {
tenantId = vpc.getUuid();
tenantName = vpc.getName();
_vpcDao.releaseFromLockTable(vpc.getId());
} else {
// use account in CS as tenant in BSN
// use network id/name as tenant id/name for non-VPC networks
tenantId = network.getUuid();
tenantName = network.getName();
}
String networkId = network.getUuid();
String hostname = dest.getHost().getName();
String nicId = nic.getUuid();
Integer vlan = Integer.valueOf(BroadcastDomainType.getValue(nic.getIsolationUri()));
String ipv4 = nic.getIPv4Address();
String mac = nic.getMacAddress();
long zoneId = network.getDataCenterId();
String vmwareVswitchLabel = _networkModel.getDefaultGuestTrafficLabel(zoneId, HypervisorType.VMware);
String[] labelArray = null;
String vswitchName = null;
if (vmwareVswitchLabel != null) {
labelArray = vmwareVswitchLabel.split(",");
vswitchName = labelArray[0];
}
// hypervisor type:
// kvm: ivs port name
// vmware: specific portgroup naming convention
String pgName = "";
if (dest.getHost().getHypervisorType() == HypervisorType.KVM) {
pgName = hostname;
} else if (dest.getHost().getHypervisorType() == HypervisorType.VMware) {
pgName = hostname + "-" + vswitchName;
}
CreateBcfAttachmentCommand cmd = new CreateBcfAttachmentCommand(tenantId, tenantName, networkId, pgName, nicId, vlan, ipv4, mac);
_bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
return true;
}
use of com.cloud.agent.api.CreateBcfAttachmentCommand in project cloudstack by apache.
the class BigSwitchBcfResourceTest method testCreateAttachmentRetryOnce.
@Test
public void testCreateAttachmentRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
_resource.configure("BigSwitchBcfResource", _parameters);
AttachmentData attachmentData = mock(AttachmentData.class);
AttachmentData.Attachment attachment = mock(AttachmentData.Attachment.class);
when(attachmentData.getAttachment()).thenReturn(attachment);
when(attachment.getId()).thenReturn("eeee");
when(_bigswitchBcfApi.createAttachment((String) any(), (String) any(), (AttachmentData) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
CreateBcfAttachmentCommand cmd = new CreateBcfAttachmentCommand("tenantid", "tenantname", "networkid", "portid", "nicId", 100, "1.2.3.4", "aa:bb:cc:dd:ee:ff");
BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
assertTrue(ans.getResult());
}
use of com.cloud.agent.api.CreateBcfAttachmentCommand in project cloudstack by apache.
the class BigSwitchBcfResourceTest method testCreateAttachmentApiException.
@Test
public void testCreateAttachmentApiException() throws ConfigurationException, BigSwitchBcfApiException {
_resource.configure("BigSwitchBcfResource", _parameters);
AttachmentData attachmentData = mock(AttachmentData.class);
AttachmentData.Attachment attachment = mock(AttachmentData.Attachment.class);
when(attachmentData.getAttachment()).thenReturn(attachment);
when(attachment.getId()).thenReturn("eeee");
doThrow(new BigSwitchBcfApiException()).when(_bigswitchBcfApi).createAttachment((String) any(), (String) any(), (AttachmentData) any());
CreateBcfAttachmentCommand cmd = new CreateBcfAttachmentCommand("tenantid", "tenantname", "networkid", "portid", "nicId", 100, "1.2.3.4", "aa:bb:cc:dd:ee:ff");
BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
assertFalse(ans.getResult());
verify(_bigswitchBcfApi, times(3)).createAttachment((String) any(), (String) any(), (AttachmentData) any());
}
use of com.cloud.agent.api.CreateBcfAttachmentCommand in project cloudstack by apache.
the class BigSwitchBcfGuestNetworkGuru method prepareMigration.
@Override
public boolean prepareMigration(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) {
bcfUtilsInit();
// get arguments for CreateBcfAttachmentCommand
// determine whether this is VPC network or stand-alone network
Vpc vpc = null;
if (network.getVpcId() != null) {
vpc = _vpcDao.acquireInLockTable(network.getVpcId());
}
String networkId = network.getUuid();
String tenantId;
String tenantName;
if (vpc != null) {
tenantId = vpc.getUuid();
tenantName = vpc.getName();
boolean released = _vpcDao.releaseFromLockTable(vpc.getId());
s_logger.debug("BCF guru release lock vpc id: " + vpc.getId() + " released? " + released);
} else {
// use network id in CS as tenant in BSN
// use network uuid as tenant id for non-VPC networks
tenantId = networkId;
tenantName = network.getName();
}
String hostname = dest.getHost().getName();
long zoneId = network.getDataCenterId();
String vmwareVswitchLabel = _networkModel.getDefaultGuestTrafficLabel(zoneId, HypervisorType.VMware);
String[] labelArray = null;
String vswitchName = null;
if (vmwareVswitchLabel != null) {
labelArray = vmwareVswitchLabel.split(",");
vswitchName = labelArray[0];
}
// hypervisor type:
// kvm: ivs port name
// vmware: specific portgroup naming convention
String pgName = "";
if (dest.getHost().getHypervisorType() == HypervisorType.KVM) {
pgName = hostname;
} else if (dest.getHost().getHypervisorType() == HypervisorType.VMware) {
pgName = hostname + "-" + vswitchName;
}
String nicId = nic.getUuid();
Integer vlan = Integer.valueOf(BroadcastDomainType.getValue(nic.getIsolationUri()));
String ipv4 = nic.getIPv4Address();
String mac = nic.getMacAddress();
CreateBcfAttachmentCommand cmd = new CreateBcfAttachmentCommand(tenantId, tenantName, networkId, pgName, nicId, vlan, ipv4, mac);
_bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
return true;
}
Aggregations