cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaya...@apache.org
Subject [4/9] git commit: updated refs/heads/master to b616522
Date Thu, 28 May 2015 11:59:21 GMT
CLOUDSTACK-8324: Resource base changes for vm ip fetch


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/7984ae52
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/7984ae52
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/7984ae52

Branch: refs/heads/master
Commit: 7984ae5283017e223259dd87958f6f5ef60bf617
Parents: 733ac2b
Author: Jayapal <jayapal@apache.org>
Authored: Wed May 20 15:49:26 2015 +0530
Committer: Jayapal <jayapal@apache.org>
Committed: Thu May 28 15:42:08 2015 +0530

----------------------------------------------------------------------
 .../CitrixGetVmIpAddressCommandWrapper.java     | 81 ++++++++++++++++++++
 .../cloud/network/guru/DirectNetworkGuru.java   |  5 +-
 2 files changed, 84 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7984ae52/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/citrix/CitrixGetVmIpAddressCommandWrapper.java
----------------------------------------------------------------------
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 0000000..889ded3
--- /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<GetVmIpAddressCommand,
Answer, CitrixResourceBase> {
+
+    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<String, String> 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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7984ae52/server/src/com/cloud/network/guru/DirectNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
index dcd3c72..18f7641 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<InsufficientCapacityException>()
{
                 @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);


Mime
View raw message