use of com.cloud.network.bigswitch.AttachmentData in project cloudstack by apache.
the class BigSwitchBcfResource method executeRequest.
private Answer executeRequest(UpdateBcfAttachmentCommand cmd, int numRetries) {
AttachmentData attachment = new AttachmentData();
attachment.getAttachment().setId(cmd.getAttachmentId());
attachment.getAttachment().setTenantName(cmd.getTenantId());
try {
String hash = _bigswitchBcfApi.modifyAttachment(cmd.getTenantId(), cmd.getNetworkId(), attachment);
return new BcfAnswer(cmd, true, "Network attachment " + cmd.getAttachmentId() + " updated", hash);
} catch (BigSwitchBcfApiException e) {
if (e.is_topologySyncRequested()) {
cmd.setTopologySyncRequested(true);
return new BcfAnswer(cmd, true, "Network attachment " + cmd.getAttachmentId() + " updated; topology sync required.");
} else {
if (numRetries > 0) {
return retry(cmd, --numRetries);
} else {
return new BcfAnswer(cmd, e);
}
}
}
}
use of com.cloud.network.bigswitch.AttachmentData in project cloudstack by apache.
the class BigSwitchBcfResource method executeRequest.
private Answer executeRequest(CreateBcfAttachmentCommand cmd, int numRetries) {
AttachmentData attachment = new AttachmentData();
attachment.getAttachment().setId(cmd.getNicId());
attachment.getAttachment().setHostId(cmd.getPortId());
attachment.getAttachment().setTenantName(cmd.getTenantName());
attachment.getAttachment().setVlan(cmd.getVlan());
attachment.getAttachment().addIpv4(cmd.getIpv4());
attachment.getAttachment().setMac(cmd.getMac());
try {
String hash = _bigswitchBcfApi.createAttachment(cmd.getTenantId(), cmd.getNetworkId(), attachment);
return new BcfAnswer(cmd, true, "network attachment " + cmd.getPortId() + " created", hash);
} catch (BigSwitchBcfApiException e) {
if (e.is_topologySyncRequested()) {
cmd.setTopologySyncRequested(true);
return new BcfAnswer(cmd, true, "network attachment " + cmd.getPortId() + " created; topology sync required.");
} else {
if (numRetries > 0) {
return retry(cmd, --numRetries);
} else {
return new BcfAnswer(cmd, e);
}
}
}
}
use of com.cloud.network.bigswitch.AttachmentData 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.network.bigswitch.AttachmentData 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.network.bigswitch.AttachmentData in project cloudstack by apache.
the class BigSwitchBcfResourceTest method testUpdateAttachmentRetryOnce.
@Test
public void testUpdateAttachmentRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
_resource.configure("BigSwitchBcfResource", _parameters);
when(_bigswitchBcfApi.modifyAttachment((String) any(), (String) any(), (AttachmentData) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
BcfAnswer ans = (BcfAnswer) _resource.executeRequest(new UpdateBcfAttachmentCommand("networkId", "portId", "tenantId", "portname"));
assertTrue(ans.getResult());
}
Aggregations