Search in sources :

Example 1 with BaremetalSwitchBackend

use of com.cloud.baremetal.networkservice.BaremetalSwitchBackend in project cloudstack by apache.

the class BaremetalVlanManagerImpl method prepareVlan.

@Override
public void prepareVlan(Network nw, DeployDestination destHost) {
    List<BaremetalRctVO> vos = rctDao.listAll();
    if (vos.isEmpty()) {
        throw new CloudRuntimeException("no rack configuration found, please call addBaremetalRct to add one");
    }
    BaremetalRctVO vo = vos.get(0);
    BaremetalRct rct = gson.fromJson(vo.getRct(), BaremetalRct.class);
    RackPair rp = findRack(rct, destHost.getHost().getPrivateMacAddress());
    if (rp == null) {
        throw new CloudRuntimeException(String.format("cannot find any rack contains host[mac:%s], please double check your rack configuration file, update it and call addBaremetalRct again", destHost.getHost().getPrivateMacAddress()));
    }
    int vlan = Integer.parseInt(Networks.BroadcastDomainType.getValue(nw.getBroadcastUri()));
    BaremetalSwitchBackend backend = getSwitchBackend(rp.rack.getL2Switch().getType());
    BaremetalVlanStruct struct = new BaremetalVlanStruct();
    struct.setHostMac(rp.host.getMac());
    struct.setPort(rp.host.getPort());
    struct.setSwitchIp(rp.rack.getL2Switch().getIp());
    struct.setSwitchPassword(rp.rack.getL2Switch().getPassword());
    struct.setSwitchType(rp.rack.getL2Switch().getType());
    struct.setSwitchUsername(rp.rack.getL2Switch().getUsername());
    struct.setVlan(vlan);
    backend.prepareVlan(struct);
}
Also used : BaremetalRctVO(com.cloud.baremetal.database.BaremetalRctVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) BaremetalSwitchBackend(com.cloud.baremetal.networkservice.BaremetalSwitchBackend) BaremetalVlanStruct(com.cloud.baremetal.networkservice.BaremetalVlanStruct)

Example 2 with BaremetalSwitchBackend

use of com.cloud.baremetal.networkservice.BaremetalSwitchBackend in project cloudstack by apache.

the class BaremetalVlanManagerImpl method releaseVlan.

@Override
public void releaseVlan(Network nw, VirtualMachineProfile vm) {
    List<BaremetalRctVO> vos = rctDao.listAll();
    if (vos.isEmpty()) {
        throw new CloudRuntimeException("no rack configuration found, please call addBaremetalRct to add one");
    }
    BaremetalRctVO vo = vos.get(0);
    BaremetalRct rct = gson.fromJson(vo.getRct(), BaremetalRct.class);
    HostVO host = hostDao.findById(vm.getVirtualMachine().getHostId());
    RackPair rp = findRack(rct, host.getPrivateMacAddress());
    assert rp != null : String.format("where is my rack???");
    int vlan = Integer.parseInt(Networks.BroadcastDomainType.getValue(nw.getBroadcastUri()));
    BaremetalVlanStruct struct = new BaremetalVlanStruct();
    struct.setHostMac(rp.host.getMac());
    struct.setPort(rp.host.getPort());
    struct.setSwitchIp(rp.rack.getL2Switch().getIp());
    struct.setSwitchPassword(rp.rack.getL2Switch().getPassword());
    struct.setSwitchType(rp.rack.getL2Switch().getType());
    struct.setSwitchUsername(rp.rack.getL2Switch().getUsername());
    struct.setVlan(vlan);
    BaremetalSwitchBackend backend = getSwitchBackend(rp.rack.getL2Switch().getType());
    backend.removePortFromVlan(struct);
}
Also used : BaremetalRctVO(com.cloud.baremetal.database.BaremetalRctVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) BaremetalSwitchBackend(com.cloud.baremetal.networkservice.BaremetalSwitchBackend) BaremetalVlanStruct(com.cloud.baremetal.networkservice.BaremetalVlanStruct) HostVO(com.cloud.host.HostVO)

Aggregations

BaremetalRctVO (com.cloud.baremetal.database.BaremetalRctVO)2 BaremetalSwitchBackend (com.cloud.baremetal.networkservice.BaremetalSwitchBackend)2 BaremetalVlanStruct (com.cloud.baremetal.networkservice.BaremetalVlanStruct)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 HostVO (com.cloud.host.HostVO)1