diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/citrix/CitrixGetVmIpAddressCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/citrix/CitrixGetVmIpAddressCommandWrapper.java new file mode 100644 index 00000000000..889ded35101 --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/citrix/CitrixGetVmIpAddressCommandWrapper.java @@ -0,0 +1,81 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.hypervisor.xenserver.resource.wrapper; + +import java.util.Map; + +import com.cloud.agent.api.GetVmIpAddressCommand; +import com.cloud.utils.net.NetUtils; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.VM; +import com.xensource.xenapi.VMGuestMetrics; +import com.xensource.xenapi.Types; +import org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; +import com.cloud.resource.CommandWrapper; +import org.apache.xmlrpc.XmlRpcException; + +public final class CitrixGetVmIpAddressCommandWrapper extends CommandWrapper { + + private static final Logger s_logger = Logger.getLogger(CitrixGetVmIpAddressCommandWrapper.class); + + @Override + public Answer execute(final GetVmIpAddressCommand command, final CitrixResourceBase citrixResourceBase) { + final Connection conn = citrixResourceBase.getConnection(); + + String vmName = command.getVmName(); + String networkCidr = command.getVmNetworkCidr(); + boolean result = false; + String errorMsg = null; + String vmIp = null; + + try { + VM vm = citrixResourceBase.getVM(conn, vmName); + VMGuestMetrics mtr = vm.getGuestMetrics(conn); + VMGuestMetrics.Record rec = mtr.getRecord(conn); + Map vmIpsMap = rec.networks; + + for (String ipAddr: vmIpsMap.values()) { + if (NetUtils.isIpWithtInCidrRange(ipAddr, networkCidr)) { + vmIp = ipAddr; + break; + } + } + + if (vmIp != null) { + s_logger.debug("VM " +vmName + " ip address got retrieved "+vmIp); + result = true; + return new Answer(command, result, vmIp); + } + + }catch (Types.XenAPIException e) { + s_logger.debug("Got exception in GetVmIpAddressCommand "+ e.getMessage()); + errorMsg = "Failed to retrived vm ip addr, exception: "+e.getMessage(); + }catch (XmlRpcException e) { + s_logger.debug("Got exception in GetVmIpAddressCommand "+ e.getMessage()); + errorMsg = "Failed to retrived vm ip addr, exception: "+e.getMessage(); + } + + return new Answer(command, result, errorMsg); + + } +} \ No newline at end of file diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java index dcd3c722d54..18f7641b3f4 100644 --- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java +++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java @@ -245,10 +245,11 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru { Transaction.execute(new TransactionCallbackWithExceptionNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) throws InsufficientVirtualNetworkCapacityException, - InsufficientAddressCapacityException { + InsufficientAddressCapacityException { if (_networkModel.isSharedNetworkWithoutServices(network.getId())) { - _ipAddrMgr.allocateDirectIp(nic, dc, vm, network, requestedIp4Addr, requestedIp6Addr); + _ipAddrMgr.allocateNicValues(nic, dc, vm, network, requestedIp4Addr, requestedIp6Addr); } else { + _ipAddrMgr.allocateDirectIp(nic, dc, vm, network, requestedIp4Addr, requestedIp6Addr); //save the placeholder nic if the vm is the Virtual router if (vm.getType() == VirtualMachine.Type.DomainRouter) { Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, null);