use of com.cloud.agent.api.CreateNetworkAnswer in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuru method implement.
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
Network implemented = super.implement(network, offering, dest, context);
int vlanTag = Integer.parseInt(BroadcastDomainType.getValue(implemented.getBroadcastUri()));
//get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
List<BrocadeVcsDeviceVO> devices = _brocadeVcsDao.listByPhysicalNetwork(physicalNetworkId);
if (devices.isEmpty()) {
s_logger.error("No Brocade VCS Switch on physical network " + physicalNetworkId);
return null;
}
for (BrocadeVcsDeviceVO brocadeVcsDevice : devices) {
HostVO brocadeVcsHost = _hostDao.findById(brocadeVcsDevice.getHostId());
// create createNetworkCmd instance and agentMgr execute it.
CreateNetworkCommand cmd = new CreateNetworkCommand(vlanTag, network.getId(), context.getDomain().getName() + "-" + context.getAccount().getAccountName());
CreateNetworkAnswer answer = (CreateNetworkAnswer) _agentMgr.easySend(brocadeVcsHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("CreateNetworkCommand failed");
s_logger.error("Unable to create network " + network.getId());
return null;
}
}
// Persist the network-vlan mapping from db
BrocadeVcsNetworkVlanMappingVO brocadeVcsNetworkVlanMapping = new BrocadeVcsNetworkVlanMappingVO(network.getId(), vlanTag);
_brocadeVcsNetworkVlanDao.persist(brocadeVcsNetworkVlanMapping);
return implemented;
}
use of com.cloud.agent.api.CreateNetworkAnswer in project cloudstack by apache.
the class BrocadeVcsResourceTest method testCreateNetworkApi.
@Test
public void testCreateNetworkApi() throws ConfigurationException, BrocadeVcsApiException {
resource.configure("BrocadeVcsResource", parameters);
when(api.createNetwork(VLAN_ID, NETWORK_ID)).thenReturn(true);
final CreateNetworkCommand cmd = new CreateNetworkCommand(VLAN_ID, NETWORK_ID, "owner");
final CreateNetworkAnswer answer = (CreateNetworkAnswer) resource.executeRequest(cmd);
//verify(api).createNetwork(VLAN_ID, NETWORK_ID);
assertTrue(answer.getResult());
}
use of com.cloud.agent.api.CreateNetworkAnswer in project cloudstack by apache.
the class BrocadeVcsResourceTest method testCreateNetworkApiException.
@Test
public void testCreateNetworkApiException() throws ConfigurationException, BrocadeVcsApiException {
resource.configure("BrocadeVcsResource", parameters);
when(api.createNetwork(VLAN_ID, NETWORK_ID)).thenThrow(new BrocadeVcsApiException());
final CreateNetworkCommand cmd = new CreateNetworkCommand(VLAN_ID, NETWORK_ID, "owner");
final CreateNetworkAnswer answer = (CreateNetworkAnswer) resource.executeRequest(cmd);
assertFalse(answer.getResult());
}
use of com.cloud.agent.api.CreateNetworkAnswer in project cloudstack by apache.
the class BrocadeVcsResourceTest method testRetries.
@Test
public void testRetries() throws ConfigurationException, BrocadeVcsApiException {
resource.configure("BrocadeVcsResource", parameters);
when(api.createNetwork(VLAN_ID, NETWORK_ID)).thenThrow(new BrocadeVcsApiException()).thenThrow(new BrocadeVcsApiException()).thenReturn(true);
final CreateNetworkCommand cmd = new CreateNetworkCommand(VLAN_ID, NETWORK_ID, "owner");
final CreateNetworkAnswer answer = (CreateNetworkAnswer) resource.executeRequest(cmd);
assertTrue(answer.getResult());
}
use of com.cloud.agent.api.CreateNetworkAnswer in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuruTest method testImplementFail.
@Test
public void testImplementFail() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VCS" }));
when(physnet.getId()).thenReturn(NETWORK_ID);
final NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
mock(DeploymentPlan.class);
final NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getBroadcastUri()).thenReturn(new URI("vlan://14"));
final DeployDestination dest = mock(DeployDestination.class);
final DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
final HostVO brocadeHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
when(brocadeHost.getId()).thenReturn(NETWORK_ID);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final List<BrocadeVcsDeviceVO> devices = mock(List.class);
when(devices.isEmpty()).thenReturn(true);
when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
final Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
final Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
final ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
when(guestGuru.implement(network, offering, dest, res)).thenReturn(network);
final CreateNetworkAnswer answer = mock(CreateNetworkAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
final Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork == null);
verify(agentmgr, times(0)).easySend(eq(NETWORK_ID), (Command) any());
}
Aggregations