Пример #1
0
 public static boolean initialize(String cluster, List<Pair> ccList) {
   if (AddressUtil.tryInit(cluster)) {
     try {
       List<Address> addrList = getStoredAddresses(cluster);
       List<String> ccListAddrs =
           Lists.transform(
               ccList,
               new Function<Pair, String>() {
                 @Override
                 public String apply(Pair p) {
                   return p.getLeft();
                 }
               });
       for (Address addr : addrList) {
         if (ccListAddrs.contains(addr.getName())) {
           Pair current = checkHasCurrentState(addr.getName(), ccList);
           if (current != null) {
             try {
               VmInstance vm = VmInstances.getInstance().lookupByInstanceIp(current.getRight());
               addr.setAssigned(vm.getInstanceId(), current.getRight());
             } catch (Exception e) {
               addr.doUnassign();
             }
           }
           addr.init();
           ccList.remove(current);
         } else {
           try {
             addr.release();
             Addresses.getInstance().deregister(addr.getName());
           } catch (Throwable e) {
             LOG.debug(e);
           }
         }
       }
       for (Pair current : ccList) {
         Address addr = AddressUtil.lookupOrCreate(cluster, current);
         try {
           VmInstance vm = VmInstances.getInstance().lookupByInstanceIp(current.getRight());
           addr.allocate(Component.eucalyptus.name());
           addr.setAssigned(vm.getInstanceId(), current.getRight());
         } catch (Exception e) {
           addr.doUnassign();
         }
         addr.init();
       }
     } catch (Throwable e) {
       clusterInit.get(cluster).set(false);
     }
     return true;
   } else {
     return false;
   }
 }
Пример #2
0
 public static void releaseAddress(String s) {
   try {
     Address addr = Addresses.getInstance().lookup(s);
     AddressUtil.releaseAddress(addr);
   } catch (NoSuchElementException e) {
     LOG.debug(e, e);
   }
 }
Пример #3
0
 public static void tryAssignSystemAddress(final VmInstance vm) {
   if (!EucalyptusProperties.disableNetworking) {
     try {
       Address newAddress = AddressUtil.allocateAddresses(vm.getPlacement(), 1).get(0);
       newAddress.setInstanceId(vm.getInstanceId());
       newAddress.setInstanceAddress(vm.getNetworkConfig().getIpAddress());
       AddressUtil.dispatchAssignAddress(newAddress, vm);
     } catch (NotEnoughResourcesAvailable notEnoughResourcesAvailable) {
       LOG.error(
           "Attempt to assign a system address for "
               + vm.getInstanceId()
               + " failed due to lack of addresses.");
     } catch (Exception e) {
       LOG.error(
           "Attempt to assign a system address for "
               + vm.getInstanceId()
               + " failed due to lack of addresses.");
     }
   }
 }
Пример #4
0
 public static synchronized List<Address> allocateAddresses(String cluster, int count)
     throws NotEnoughResourcesAvailable {
   boolean doDynamic = true;
   AddressUtil.updateAddressingMode();
   doDynamic = Addresses.doDynamicAddressing();
   List<Address> addressList = null;
   if (doDynamic) {
     addressList = Addresses.getInstance().getDynamicSystemAddresses(cluster, count);
   } else {
     addressList = Addresses.getInstance().getStaticSystemAddresses(count);
   }
   return addressList;
 }
Пример #5
0
 public static List<Address> tryAssignSystemAddresses(ResourceToken token) throws Exception {
   if (!EucalyptusProperties.disableNetworking) {
     try {
       List<Address> newAddresses =
           AddressUtil.allocateAddresses(token.getCluster(), token.getAmount());
       return newAddresses;
     } catch (Exception e) {
       throw e;
     }
   } else {
     throw new NotEnoughResourcesAvailable(
         "Not enough resources available: addresses (not supported by cluster).");
   }
 }
Пример #6
0
 public static void update(String cluster, List<Pair> ccList) {
   List<String> ccListAddrs =
       Lists.transform(
           ccList,
           new Function<Pair, String>() {
             @Override
             public String apply(Pair p) {
               return p.getLeft();
             }
           });
   for (Pair p : ccList) {
     Address address = AddressUtil.lookupOrCreate(cluster, p);
     try {
       InetAddress addr = Inet4Address.getByName(p.getRight());
       VmInstance vm;
       try {
         vm = VmInstances.getInstance().lookupByInstanceIp(p.getRight());
         if (Address.UNALLOCATED_USERID.equals(address.getUserId())) {
           address.allocate(Component.eucalyptus.name());
         }
         if (!address.isAssigned()) {
           address.setAssigned(vm.getInstanceId(), p.getRight());
         }
         orphans.remove(address.getName());
       } catch (Exception e1) {
         if (!addr.isLoopbackAddress() && !AddressUtil.checkForPendingVm()) {
           AddressUtil.handleOrphan(cluster, address);
         } else {
           orphans.remove(address.getName());
         }
       }
     } catch (UnknownHostException e1) {
       LOG.debug(e1, e1);
       orphans.remove(address.getName());
     }
   }
 }
Пример #7
0
 public static void unassignAddressFromVm(Address address, VmInstance vm) {
   AddressUtil.markAddressUnassigned(address);
   AddressUtil.dispatchUnassignAddress(address, vm);
 }
Пример #8
0
 public static void dispatchAssignAddress(String addr, VmInstance vm) {
   Address address = Addresses.getInstance().lookup(addr);
   AddressUtil.dispatchAssignAddress(address, vm);
 }
Пример #9
0
 public static void assignAddressToVm(Address address, VmInstance vm)
     throws EucalyptusCloudException {
   AddressUtil.markAddressAssigned(address, vm);
   AddressUtil.dispatchAssignAddress(address, vm);
 }