public static ModifyPropertyValueResponseType modifyProperty(ModifyPropertyValueType request) throws EucalyptusCloudException { ModifyPropertyValueResponseType reply = request.getReply(); if (INTERNAL_OP.equals(request.getName())) { if (!Contexts.lookup().hasAdministrativePrivileges()) { throw new EucalyptusCloudException("You are not authorized to interact with this service."); } LOG.debug("Performing euca operation: \n" + request.getValue()); try { reply.setName(INTERNAL_OP); reply.setValue("" + Groovyness.eval(request.getValue())); reply.setOldValue("executed successfully."); } catch (Exception ex) { LOG.error(ex, ex); reply.setName(INTERNAL_OP); reply.setOldValue("euca operation failed because of: " + ex.getMessage()); reply.setValue(Exceptions.string(ex)); } } else { try { ConfigurableProperty entry = PropertyDirectory.getPropertyEntry(request.getName()); String oldValue = "********"; if (!entry.getWidgetType().equals(ConfigurableFieldType.KEYVALUEHIDDEN)) { oldValue = entry.getValue(); } reply.setOldValue(oldValue); Boolean reset = request.getReset(); if (reset != null) { if (Boolean.TRUE.equals(reset)) { entry.setValue(entry.getDefaultValue()); } } else { // if property is ReadOnly it should not be set by user if (!entry.getReadOnly()) { try { String inValue = request.getValue(); entry.setValue((inValue == null) ? "" : inValue); } catch (Exception e) { entry.setValue(oldValue); Exceptions.findAndRethrow(e, EucalyptusCloudException.class); throw e; } } } reply.setValue(entry.getValue()); reply.setName(request.getName()); } catch (IllegalAccessException e) { throw new EucalyptusCloudException("Failed to set property: " + e.getMessage()); } catch (EucalyptusCloudException e) { throw e; } catch (Throwable e) { throw new EucalyptusCloudException(e); } } return reply; }
public static DescribePropertiesResponseType describeProperties( final DescribePropertiesType request) throws EucalyptusCloudException { DescribePropertiesResponseType reply = request.getReply(); List<Property> props = reply.getProperties(); final Predicate<ConfigurableProperty> filter = new Predicate<ConfigurableProperty>() { public boolean apply(final ConfigurableProperty input) { if (request.getProperties().isEmpty()) { return true; } else if (request.getProperties().contains(input.getQualifiedName())) { return true; } else { for (String propRequest : request.getProperties()) { if (input.getQualifiedName().startsWith(propRequest)) { return true; } } } return false; } }; for (ConfigurableProperty entry : Iterables.filter(PropertyDirectory.getPropertyEntrySet(), filter)) { if (filter.apply(entry)) { String value = "********"; if (!entry.getWidgetType().equals(ConfigurableFieldType.KEYVALUEHIDDEN)) value = entry.getValue(); props.add( new Property( entry.getQualifiedName(), value, entry.getDescription(), entry.getDefaultValue(), entry.getReadOnly())); } } return reply; }
public Address allocateNext(final OwnerFullName userId) throws NotEnoughResourcesException { int numSystemReserved = 0; try { ConfigurableProperty p = PropertyDirectory.getPropertyEntry("cloud.addresses.systemreservedpublicaddresses"); if (p != null) numSystemReserved = Integer.parseInt(p.getValue()); } catch (IllegalAccessException e) { LOG.error("Can't find the 'systemreservedpublicaddresses' property"); numSystemReserved = 0; } if ((Addresses.getInstance().listDisabledValues().size() - numSystemReserved) < 1) { throw new NotEnoughResourcesException(ExceptionList.ERR_SYS_INSUFFICIENT_ADDRESS_CAPACITY); } Predicate<Address> predicate = RestrictedTypes.filterPrivileged(); final Address addr = Addresses.getInstance().enableFirst(predicate).allocate(userId); LOG.debug("Allocated address for public addressing: " + addr.toString()); if (addr == null) { LOG.debug(LogUtil.header(Addresses.getInstance().toString())); throw new NotEnoughResourcesException(ExceptionList.ERR_SYS_INSUFFICIENT_ADDRESS_CAPACITY); } return addr; }