@Override public String call(VmNicVO arg) { return arg.getUuid(); } });
@Override public VmNicVO call(VmNicVO arg) { return arg.getUuid().equals(nicUuid) ? arg : null; } });
@Override public VmNicVO call(VmNicVO arg) { return arg.getUuid().equals(nicUuid) ? arg : null; } })
@Override public VmNicVO call(VmNicVO arg) { return arg.getUuid().equals(nic.getUuid()) ? null : arg; } });
private LoadBalancerStruct makeStruct() { LoadBalancerStruct struct = new LoadBalancerStruct(); struct.setLb(reloadAndGetInventory()); List<String> activeNicUuids = new ArrayList<String>(); for (LoadBalancerListenerVO l : self.getListeners()) { activeNicUuids.addAll(CollectionUtils.transformToList(l.getVmNicRefs(), new Function<String, LoadBalancerListenerVmNicRefVO>() { @Override public String call(LoadBalancerListenerVmNicRefVO arg) { return arg.getStatus() == LoadBalancerVmNicStatus.Active || arg.getStatus() == LoadBalancerVmNicStatus.Pending ? arg.getVmNicUuid() : null; } })); } if (activeNicUuids.isEmpty()) { struct.setVmNics(new HashMap<String, VmNicInventory>()); } else { SimpleQuery<VmNicVO> nq = dbf.createQuery(VmNicVO.class); nq.add(VmNicVO_.uuid, Op.IN, activeNicUuids); List<VmNicVO> nicvos = nq.list(); Map<String, VmNicInventory> m = new HashMap<String, VmNicInventory>(); for (VmNicVO n : nicvos) { m.put(n.getUuid(), VmNicInventory.valueOf(n)); } struct.setVmNics(m); } struct.setListeners(LoadBalancerListenerInventory.valueOf(self.getListeners())); return struct; }
private LoadBalancerStruct makeStruct(LoadBalancerVO vo) { LoadBalancerStruct struct = new LoadBalancerStruct(); struct.setLb(LoadBalancerInventory.valueOf(vo)); List<String> activeNicUuids = new ArrayList<String>(); for (LoadBalancerListenerVO l : vo.getListeners()) { activeNicUuids.addAll(CollectionUtils.transformToList(l.getVmNicRefs(), new Function<String, LoadBalancerListenerVmNicRefVO>() { @Override public String call(LoadBalancerListenerVmNicRefVO arg) { return arg.getStatus() == LoadBalancerVmNicStatus.Active || arg.getStatus() == LoadBalancerVmNicStatus.Pending ? arg.getVmNicUuid() : null; } })); } if (activeNicUuids.isEmpty()) { struct.setVmNics(new HashMap<String, VmNicInventory>()); } else { SimpleQuery<VmNicVO> nq = dbf.createQuery(VmNicVO.class); nq.add(VmNicVO_.uuid, Op.IN, activeNicUuids); List<VmNicVO> nicvos = nq.list(); Map<String, VmNicInventory> m = new HashMap<String, VmNicInventory>(); for (VmNicVO n : nicvos) { m.put(n.getUuid(), VmNicInventory.valueOf(n)); } struct.setVmNics(m); } struct.setListeners(LoadBalancerListenerInventory.valueOf(vo.getListeners())); return struct; }
@Override public void rollback(final FlowRollback chain, Map data) { VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); List<DetachIpAddressFromVmNicMsg> msgs = new ArrayList<>(); /* reload vmnic */ List<VmNicVO> vmNicVOS = Q.New(VmNicVO.class).eq(VmNicVO_.vmInstanceUuid, spec.getVmInventory().getUuid()).list(); for (VmNicVO nic : vmNicVOS) { List<String> ipUuids = VmNicHelper.getCanDetachL3List(VmNicInventory.valueOf(nic), spec.getL3Networks()); for (String uuid : ipUuids) { DetachIpAddressFromVmNicMsg msg = new DetachIpAddressFromVmNicMsg(); msg.setVmNicUuid(nic.getUuid()); msg.setUsedIpUuid(uuid); bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, nic.getUuid()); msgs.add(msg); } } new While<>(msgs).each((msg, comp) -> bus.send(msg, new CloudBusCallBack(comp) { @Override public void run(MessageReply reply) { comp.done(); } })).run(new NoErrorCompletion(chain) { @Override public void done() { chain.rollback(); } }); } }
private void handle(final APIDetachL3NetworkFromVmMsg msg) { VmNicVO vmNicVO = dbf.findByUuid(msg.getVmNicUuid(), VmNicVO.class); String vmNicAccountUuid = acntMgr.getOwnerAccountUuidOfResource(vmNicVO.getUuid());
@Override public void prepareDbInitialValue() { List<IpRangeVO> ipRangeVOS = Q.New(IpRangeVO.class).isNull(IpRangeVO_.prefixLen).list(); for (IpRangeVO ipr : ipRangeVOS) { ipr.setPrefixLen(NetworkUtils.getPrefixLengthFromNetwork(ipr.getNetmask())); } if (!ipRangeVOS.isEmpty()) { dbf.updateCollection(ipRangeVOS); } List<VmNicVO> nics = Q.New(VmNicVO.class).notNull(VmNicVO_.usedIpUuid).list(); List<UsedIpVO> ips = new ArrayList<>(); for (VmNicVO nic : nics) { UsedIpVO ip = Q.New(UsedIpVO.class).eq(UsedIpVO_.uuid, nic.getUsedIpUuid()).isNull(UsedIpVO_.vmNicUuid).find(); if (ip != null) { ip.setVmNicUuid(nic.getUuid()); ips.add(ip); } } if (!ips.isEmpty()) { dbf.updateCollection(ips); } } }
AttachL3NetworkToVmNicMsg msg = new AttachL3NetworkToVmNicMsg(); msg.setL3NetworkUuid(uuid); msg.setVmNicUuid(nic.getUuid()); String staticIp = vmStaticIps.get(uuid); if (staticIp != null) { msg.setStaticIp(staticIp); bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, nic.getUuid()); msgs.add(msg);
private void validateStaticIPv4(VmNicVO vmNicVO, L3NetworkVO l3NetworkVO, String ip) { if (!NetworkUtils.isIpv4Address(ip)) { throw new ApiMessageInterceptionException(argerr("%s is not a valid IPv4 address", ip)); } for (UsedIpVO ipVo : vmNicVO.getUsedIps()) { if (ipVo.getL3NetworkUuid().equals(l3NetworkVO.getUuid())) { IpRangeVO rangeVO = dbf.findByUuid(ipVo.getIpRangeUuid(), IpRangeVO.class); if (ipVo.getIp().equals(ip)) { throw new ApiMessageInterceptionException(argerr("ip address [%s] already set to vmNic [uuid:%s]", ip, vmNicVO.getUuid())); } if (!NetworkUtils.isIpv4InCidr(ip, rangeVO.getNetworkCidr())) { throw new ApiMessageInterceptionException(argerr("ip address [%s] is not in ip range [%s]", ip, rangeVO.getNetworkCidr())); } } } }
private void validateStaticIPv6(VmNicVO vmNicVO, L3NetworkVO l3NetworkVO, String ip) { if (!IPv6NetworkUtils.isIpv6Address(ip)) { throw new ApiMessageInterceptionException(argerr("%s is not a valid IPv6 address", ip)); } for (UsedIpVO ipVo : vmNicVO.getUsedIps()) { if (ipVo.getL3NetworkUuid().equals(l3NetworkVO.getUuid())) { if (ip.equals(ipVo.getIp())) { throw new ApiMessageInterceptionException(argerr("ip address [%s] already set to vmNic [uuid:%s]", ip, vmNicVO.getUuid())); } IpRangeVO rangeVO = dbf.findByUuid(ipVo.getIpRangeUuid(), IpRangeVO.class); if (!IPv6NetworkUtils.isIpv6InRange(ip, rangeVO.getStartIp(), rangeVO.getEndIp())) { throw new ApiMessageInterceptionException(argerr("ip address [%s] is not in ip range [startIp %s, endIp %s]", ip, rangeVO.getStartIp(), rangeVO.getEndIp())); } } } }
@Override public void run(MessageReply reply) { if (reply.isSuccess()) { AllocateIpReply areply = reply.castReply(); UsedIpInventory ipInventory = areply.getIpInventory(); for (VmNicExtensionPoint ext : pluginRgty.getExtensionList(VmNicExtensionPoint.class)) { ext.afterAddIpAddress(vmNicVO.getUuid(), ipInventory.getUuid()); } data.put(VmInstanceConstant.Params.UsedIPInventory.toString(), ipInventory); VmNicInventory nicInv = VmNicInventory.valueOf(dbf.findByUuid(nic.getUuid(), VmNicVO.class)); new DualStackNicSecondaryNetworksOperator().createSecondaryNetworksByVmNic(nicInv, l3.getUuid()); trigger.next(); } else { trigger.fail(reply.getError()); } } });
logger.debug(String.format("updated metadata of vmnic[uuid: %s]", vo.getUuid()));
to.nicUuid = nic.getUuid(); to.vip = eip.getVipIp(); to.vipUuid = eip.getVipUuid();
vo.setSecurityGroupUuid(msg.getSecurityGroupUuid()); vo.setVmInstanceUuid(nic.getVmInstanceUuid()); vo.setVmNicUuid(nic.getUuid()); vo.setUuid(Platform.getUuid()); refs.add(vo);
@Override public void setup() { vo.setVmNicUuid(vmNic.getUuid()); vo.setGuestIp(vmNic.getIp()); final PortForwardingRuleVO pvo = dbf.updateAndRefresh(vo);
public static VmNicInventory valueOf(VmNicVO vo) { VmNicInventory inv = new VmNicInventory(); inv.setUuid(vo.getUuid()); inv.setVmInstanceUuid(vo.getVmInstanceUuid()); inv.setUsedIpUuid(vo.getUsedIpUuid()); inv.setL3NetworkUuid(vo.getL3NetworkUuid()); inv.setInternalName(vo.getInternalName()); inv.setIp(vo.getIp()); inv.setMac(vo.getMac()); inv.setHypervisorType(vo.getHypervisorType()); inv.setDeviceId(vo.getDeviceId()); inv.setCreateDate(vo.getCreateDate()); inv.setLastOpDate(vo.getLastOpDate()); inv.setMetaData(vo.getMetaData()); inv.setNetmask(vo.getNetmask()); inv.setGateway(vo.getGateway()); inv.setIpVersion(vo.getIpVersion()); inv.setUsedIps(UsedIpInventory.valueOf(vo.getUsedIps())); return inv; }
@Override protected void scripts() { String acntUuid = Account.getAccountUuidOfResource(spec.getVmInventory().getUuid()); spec.getDestNics().forEach(nic -> { VmNicVO nvo = new VmNicVO(); nvo.setUuid(nic.getUuid()); nvo.setDeviceId(nic.getDeviceId()); nvo.setIp(nic.getIp()); nvo.setL3NetworkUuid(nic.getL3NetworkUuid()); nvo.setMac(nic.getMac()); nvo.setHypervisorType(nic.getHypervisorType()); nvo.setUsedIpUuid(nic.getUsedIpUuid()); nvo.setGateway(nic.getGateway()); nvo.setNetmask(nic.getNetmask()); nvo.setVmInstanceUuid(nic.getVmInstanceUuid()); nvo.setMetaData(nic.getMetaData()); nvo.setInternalName(nic.getInternalName()); nvo.setAccountUuid(acntUuid); nvo.setIpVersion(nic.getIpVersion()); persist(nvo); if (nic.getUsedIpUuid() != null) { SQL.New(UsedIpVO.class).eq(UsedIpVO_.uuid, nic.getUsedIpUuid()).set(UsedIpVO_.vmNicUuid, nvo.getUuid()).update(); } }); ApplianceVmVO apvm = findByUuid(spec.getVmInventory().getUuid(), ApplianceVmVO.class); apvm.setManagementNetworkUuid(mgmtNic.getL3NetworkUuid()); merge(apvm); } }.execute();
PortForwardingRuleVO vo = dbf.findByUuid(msg.getRuleUuid(), PortForwardingRuleVO.class); VmNicVO nicvo = dbf.findByUuid(msg.getVmNicUuid(), VmNicVO.class); vo.setVmNicUuid(nicvo.getUuid()); vo.setGuestIp(nicvo.getIp()); final PortForwardingRuleVO prvo = dbf.updateAndRefresh(vo);