Search in sources :

Example 56 with NicVO

use of com.cloud.vm.NicVO in project cloudstack by apache.

the class BaremetalKickStartServiceImpl method preparePxeInAdvancedZone.

private boolean preparePxeInAdvancedZone(VirtualMachineProfile profile, NicProfile nic, Network network, DeployDestination dest, ReservationContext context) throws Exception {
    DomainRouterVO vr = getVirtualRouter(network);
    List<NicVO> nics = _nicDao.listByVmId(vr.getId());
    NicVO mgmtNic = null;
    for (NicVO nicvo : nics) {
        if (ControlNetworkGuru.class.getSimpleName().equals(nicvo.getReserver())) {
            mgmtNic = nicvo;
            break;
        }
    }
    if (mgmtNic == null) {
        throw new CloudRuntimeException(String.format("cannot find management nic on virtual router[id:%s]", vr.getId()));
    }
    String internalServerIp = _configDao.getValue(Config.BaremetalInternalStorageServer.key());
    if (internalServerIp == null) {
        throw new CloudRuntimeException(String.format("please specify 'baremetal.internal.storage.server.ip', which is the http server/nfs server storing kickstart files and ISO files, in global setting"));
    }
    List<String> tuple = parseKickstartUrl(profile);
    String cmd = String.format("/opt/cloud/bin/prepare_pxe.sh %s %s %s %s %s %s", tuple.get(1), tuple.get(2), profile.getTemplate().getUuid(), String.format("01-%s", nic.getMacAddress().replaceAll(":", "-")).toLowerCase(), tuple.get(0), nic.getMacAddress().toLowerCase());
    s_logger.debug(String.format("prepare pxe on virtual router[ip:%s], cmd: %s", mgmtNic.getIPv4Address(), cmd));
    Pair<Boolean, String> ret = SshHelper.sshExecute(mgmtNic.getIPv4Address(), 3922, "root", getSystemVMKeyFile(), null, cmd);
    if (!ret.first()) {
        throw new CloudRuntimeException(String.format("failed preparing PXE in virtual router[id:%s], because %s", vr.getId(), ret.second()));
    }
    //String internalServerIp = "10.223.110.231";
    cmd = String.format("/opt/cloud/bin/baremetal_snat.sh %s %s %s", mgmtNic.getIPv4Address(), internalServerIp, mgmtNic.getIPv4Gateway());
    s_logger.debug(String.format("prepare SNAT on virtual router[ip:%s], cmd: %s", mgmtNic.getIPv4Address(), cmd));
    ret = SshHelper.sshExecute(mgmtNic.getIPv4Address(), 3922, "root", getSystemVMKeyFile(), null, cmd);
    if (!ret.first()) {
        throw new CloudRuntimeException(String.format("failed preparing PXE in virtual router[id:%s], because %s", vr.getId(), ret.second()));
    }
    return true;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) ControlNetworkGuru(com.cloud.network.guru.ControlNetworkGuru)

Example 57 with NicVO

use of com.cloud.vm.NicVO in project cloudstack by apache.

the class BaremetalPxeManagerImpl method addUserData.

@Override
public boolean addUserData(NicProfile nic, VirtualMachineProfile profile) {
    UserVmVO vm = _vmDao.findById(profile.getVirtualMachine().getId());
    _vmDao.loadDetails(vm);
    String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText();
    String zoneName = _dcDao.findById(vm.getDataCenterId()).getName();
    NicVO nvo = _nicDao.findById(nic.getId());
    VmDataCommand cmd = new VmDataCommand(nvo.getIPv4Address(), vm.getInstanceName(), _ntwkModel.getExecuteInSeqNtwkElmtCmd());
    // if you add new metadata files, also edit systemvm/patches/debian/config/var/www/html/latest/.htaccess
    cmd.addVmData("userdata", "user-data", vm.getUserData());
    cmd.addVmData("metadata", "service-offering", StringUtils.unicodeEscape(serviceOffering));
    cmd.addVmData("metadata", "availability-zone", StringUtils.unicodeEscape(zoneName));
    cmd.addVmData("metadata", "local-ipv4", nic.getIPv4Address());
    cmd.addVmData("metadata", "local-hostname", StringUtils.unicodeEscape(vm.getInstanceName()));
    cmd.addVmData("metadata", "public-ipv4", nic.getIPv4Address());
    cmd.addVmData("metadata", "public-hostname", StringUtils.unicodeEscape(vm.getInstanceName()));
    cmd.addVmData("metadata", "instance-id", String.valueOf(vm.getUuid()));
    cmd.addVmData("metadata", "vm-id", String.valueOf(vm.getInstanceName()));
    cmd.addVmData("metadata", "public-keys", null);
    String cloudIdentifier = _configDao.getValue("cloud.identifier");
    if (cloudIdentifier == null) {
        cloudIdentifier = "";
    } else {
        cloudIdentifier = "CloudStack-{" + cloudIdentifier + "}";
    }
    cmd.addVmData("metadata", "cloud-identifier", cloudIdentifier);
    List<PhysicalNetworkVO> phys = _phynwDao.listByZone(vm.getDataCenterId());
    if (phys.isEmpty()) {
        throw new CloudRuntimeException(String.format("Cannot find physical network in zone %s", vm.getDataCenterId()));
    }
    if (phys.size() > 1) {
        throw new CloudRuntimeException(String.format("Baremetal only supports one physical network in zone, but zone %s has %s physical networks", vm.getDataCenterId(), phys.size()));
    }
    PhysicalNetworkVO phy = phys.get(0);
    QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
    //TODO: handle both kickstart and PING
    //sc.addAnd(sc.getEntity().getPodId(), Op.EQ, vm.getPodIdToDeployIn());
    sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, phy.getId());
    BaremetalPxeVO pxeVo = sc.find();
    if (pxeVo == null) {
        throw new CloudRuntimeException("No PXE server found in pod: " + vm.getPodIdToDeployIn() + ", you need to add it before starting VM");
    }
    try {
        Answer ans = _agentMgr.send(pxeVo.getHostId(), cmd);
        if (!ans.getResult()) {
            s_logger.debug(String.format("Add userdata to vm:%s failed because %s", vm.getInstanceName(), ans.getDetails()));
            return false;
        } else {
            return true;
        }
    } catch (Exception e) {
        s_logger.debug(String.format("Add userdata to vm:%s failed", vm.getInstanceName()), e);
        return false;
    }
}
Also used : Answer(com.cloud.agent.api.Answer) UserVmVO(com.cloud.vm.UserVmVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VmDataCommand(com.cloud.agent.api.routing.VmDataCommand) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NicVO(com.cloud.vm.NicVO) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) BaremetalPxeVO(com.cloud.baremetal.database.BaremetalPxeVO)

Example 58 with NicVO

use of com.cloud.vm.NicVO in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final SshKeyToRouterRules sshkey) throws ResourceUnavailableException {
    final VirtualRouter router = sshkey.getRouter();
    final VirtualMachineProfile profile = sshkey.getProfile();
    final String sshKeystr = sshkey.getSshPublicKey();
    final UserVmVO userVM = sshkey.getUserVM();
    final Commands commands = new Commands(Command.OnError.Stop);
    final NicVO nicVo = sshkey.getNicVo();
    final VMTemplateVO template = sshkey.getTemplate();
    if (template != null && template.getEnablePassword()) {
        _commandSetupHelper.createPasswordCommand(router, profile, nicVo, commands);
    }
    _commandSetupHelper.createVmDataCommand(router, userVM, nicVo, sshKeystr, commands);
    return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Commands(com.cloud.agent.manager.Commands) VMTemplateVO(com.cloud.storage.VMTemplateVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 59 with NicVO

use of com.cloud.vm.NicVO in project cloudstack by apache.

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final UserdataPwdRules userdata) throws ResourceUnavailableException {
    final VirtualRouter router = userdata.getRouter();
    final Commands commands = new Commands(Command.OnError.Stop);
    final VirtualMachineProfile profile = userdata.getProfile();
    final NicVO nicVo = userdata.getNicVo();
    final UserVmVO userVM = userdata.getUserVM();
    _commandSetupHelper.createPasswordCommand(router, profile, nicVo, commands);
    _commandSetupHelper.createVmDataCommand(router, userVM, nicVo, userVM.getDetail("SSH.PublicKey"), commands);
    return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Commands(com.cloud.agent.manager.Commands) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 60 with NicVO

use of com.cloud.vm.NicVO in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final UserdataToRouterRules userdata) throws ResourceUnavailableException {
    final VirtualRouter router = userdata.getRouter();
    final UserVmVO userVM = userdata.getUserVM();
    final NicVO nicVo = userdata.getNicVo();
    final Commands commands = new Commands(Command.OnError.Stop);
    _commandSetupHelper.createVmDataCommand(router, userVM, nicVo, null, commands);
    return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Commands(com.cloud.agent.manager.Commands) NicVO(com.cloud.vm.NicVO) VirtualRouter(com.cloud.network.router.VirtualRouter)

Aggregations

NicVO (com.cloud.vm.NicVO)86 NetworkVO (com.cloud.network.dao.NetworkVO)33 ArrayList (java.util.ArrayList)21 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 NicProfile (com.cloud.vm.NicProfile)15 VMInstanceVO (com.cloud.vm.VMInstanceVO)13 DataCenterVO (com.cloud.dc.DataCenterVO)12 Commands (com.cloud.agent.manager.Commands)11 Network (com.cloud.network.Network)11 HostVO (com.cloud.host.HostVO)10 UserVmVO (com.cloud.vm.UserVmVO)10 Answer (com.cloud.agent.api.Answer)9 NetworkGuru (com.cloud.network.guru.NetworkGuru)9 Nic (com.cloud.vm.Nic)9 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)9 Test (org.junit.Test)9 DataCenter (com.cloud.dc.DataCenter)7 IPAddressVO (com.cloud.network.dao.IPAddressVO)7 VirtualRouter (com.cloud.network.router.VirtualRouter)7