java
17 TopicsGetting Started with iControl Code Samples
Problem this snippet solves: This repository on github is for the full scripts highlighted in the Getting Started with iControl article series. Developed against BIG-IP TMOS version 12.0, but should work in most versions 11.6+. How to use this snippet: Choose your language and iControl portal of choice to start investigating iControl in your environment. Target audience: beginners. Code : https://github.com/f5devcentral/iControl-GettingStarted Tested this on version: 12.0832Views0likes0CommentsJava System Info
Problem this snippet solves: This Java application illustrates how to query system information from a BIG-IP with Java. This sample is the companion code for the "Getting Started With iControl And Java - Setting Up Eclipse" Tech Tip on DevCentral. It illustrates how to setup the iControl interfaces object and query system information from the BIG-IP with Java and iControl. Code : public class SystemInfo { public iControl.Interfaces m_interfaces = new iControl.Interfaces(); public void usage() { System.out.println("Usage: SystemInfo hostname username password"); } public void Run(String [] args) throws Exception { if ( args.length < 3 ) { usage(); } else { String host = args[0]; String user = args[1]; String pass = args[2]; boolean bInit = m_interfaces.initialize(host, user, pass); if ( bInit ) { getSystemInformation(); } } } public void getSystemInformation() throws Exception { iControl.SystemSystemInformation sysInfo = m_interfaces.getSystemSystemInfo().get_system_information(); System.out.println("======================================================"); System.out.println(" System Information"); System.out.println("------------------------------------------------------"); System.out.println("System Name : " + sysInfo.getSystem_name()); System.out.println("Host name : " + sysInfo.getHost_name()); System.out.println("OS Release : " + sysInfo.getOs_release()); System.out.println("OS Machine : " + sysInfo.getOs_machine()); System.out.println("OS Version : " + sysInfo.getOs_version()); System.out.println("Platform : " + sysInfo.getPlatform()); System.out.println("Product Category : " + sysInfo.getProduct_category()); System.out.println("Chassis Serial : " + sysInfo.getChassis_serial()); System.out.println("Switch Board Serial : " + sysInfo.getSwitch_board_serial()); System.out.println("Switch Board Part Revision : " + sysInfo.getSwitch_board_part_revision()); System.out.println("Host Board Serial : " + sysInfo.getHost_board_serial()); System.out.println("host Board Part Revision : " + sysInfo.getHost_board_part_revision()); System.out.println("Annunciator Board Serial : " + sysInfo.getAnnunciator_board_serial()); System.out.println("Annunciator Board Part Revision : " + sysInfo.getAnnunciator_board_part_revision()); } /** * @param args */ public static void main(String[] args) { try { SystemInfo sysInfo = new SystemInfo(); sysInfo.Run(args); } catch(Exception ex) { ex.printStackTrace(System.out); } } }366Views0likes1CommentJava Trust Provider
Problem this snippet solves: This example java class allows access to the JSSE Trust Layer allowing access to self-signed server certificates for HTTPS based SOAP connections. Code : /* * The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5 * Software Development Kit for iControl"; you may not use this file except in * compliance with the License. The License is included in the iControl * Software Development Kit. * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is iControl Code and related documentation * distributed by F5. * * The Initial Developer of the code is Jacob Gilley. * Portions created by F5 are Copyright (C) 1996-2004 F5 Networks * Inc. All Rights Reserved. iControl (TM) is a registered trademark of * F5 Networks, Inc. * * Alternatively, the contents of this file may be used under the terms * of the GNU General Public License (the "GPL"), in which case the * provisions of GPL are applicable instead of those above. If you wish * to allow use of your version of this file only under the terms of the * GPL and not to allow others to use your version of this file under the * License, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the GPL. * If you do not delete the provisions above, a recipient may use your * version of this file under either the License or the GPL. */ import java.security.AccessController; import java.security.InvalidAlgorithmParameterException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.PrivilegedAction; import java.security.Security; import java.security.cert.X509Certificate; import javax.net.ssl.ManagerFactoryParameters; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactorySpi; import javax.net.ssl.X509TrustManager; public final class XTrustProvider extends java.security.Provider { private final static String NAME = "XTrustJSSE"; private final static String INFO = "XTrust JSSE Provider (implements trust factory with truststore validation disabled)"; private final static double VERSION = 1.0D; public XTrustProvider() { super(NAME, VERSION, INFO); AccessController.doPrivileged( new PrivilegedAction() { public Object run() { put("TrustManagerFactory." + TrustManagerFactoryImpl.getAlgorithm(), TrustManagerFactoryImpl.class.getName()); return null; } } ); } public static void install() { if(Security.getProvider(NAME) == null) { Security.insertProviderAt(new XTrustProvider(), 2); Security.setProperty("ssl.TrustManagerFactory.algorithm", TrustManagerFactoryImpl.getAlgorithm()); } } public final static class TrustManagerFactoryImpl extends TrustManagerFactorySpi { public TrustManagerFactoryImpl() { } public static String getAlgorithm() { return "XTrust509"; } protected void engineInit(KeyStore keystore) throws KeyStoreException { } protected void engineInit(ManagerFactoryParameters mgrparams) throws InvalidAlgorithmParameterException { throw new InvalidAlgorithmParameterException(XTrustProvider.NAME + " does not use ManagerFactoryParameters"); } protected TrustManager[] engineGetTrustManagers() { return new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }; } } }358Views0likes2CommentsJava Pool Member Control
Problem this snippet solves: This Java application allows for the graceful shutdown of a pool member. As an added bonus it also allows you to query pools, pool members, pool member status, and enable and disable the pool members. This question comes up quite often here on DevCentral: "How can I gracefully shut down my servers for maintenance without disrupting current user sessions?". In fact, I answered this question just the other day again in the iControl forum and figured I'd throw out an application that accomplished this. So I went about writing this application to allow for the graceful shutdown of a given pool member. Of course, the application wouldn't be complete without listing the pools and members for a specified pool as well as allowing for enabling and disabling of the server so I went ahead and included those pieces as a bonus. Code : public class PoolMemberControl { public iControl.Interfaces m_interfaces = new iControl.Interfaces(); public void Run(String [] args) throws Exception { if ( args.length < 3 ) { usage(); } else { boolean init = m_interfaces.initialize(args[0], args[1], args[2]); if ( init ) { if ( args.length == 3) { getPoolList(); } else if ( args.length == 4) { getPoolMembers(args[3]); } else if ( args.length == 5) { getPoolMemberStatus(args[3], args[4]); } else if (args.length == 6) { if ( args[5].equals("enable")) { enablePoolMember(args[3],args[4]); } else { disablePoolMember(args[3],args[4]); } } } } } public void getPoolList() throws Exception { String [] pool_list = m_interfaces.getLocalLBPool().get_list(); System.out.println("Available Pools"); for(int i=0; i 0 ) { iControl.LocalLBPoolMemberMemberStatistics [] memberStatsA = m_interfaces.getLocalLBPoolMember().get_statistics(pool_list, memberDefAofA); iControl.LocalLBPoolMemberMemberStatistics memberStats = memberStatsA[0]; iControl.LocalLBPoolMemberMemberStatisticEntry [] statsEntryA = memberStats.getStatistics(); iControl.LocalLBPoolMemberMemberStatisticEntry statsEntry = statsEntryA[0]; iControl.CommonStatistic [] statsA = statsEntry.getStatistics(); for(int i=0; i338Views0likes2CommentsGet Task Status (Java code sample)
Problem this snippet solves: This Java client code sample uses Enterprise Manager's device inventory to get the status for a specific task executed by the referenced Enterprise Manager. Code : /** * A class for testing the Management::EM::get_task_status iControl interface. */ public class ManagementEMGetTaskStatus { private static int MIN_ARGS = 3; private static String USAGE = "ManagementEMGetTaskStatus " + "[ ] ..."; private static int EM_PORT = 443; /** * The main method. * * @param args command line arguments */ public static void main(String[] args) { if (args.length < MIN_ARGS) { System.err.println("Usage: " + USAGE); System.exit(1); } String emAddress = args[0]; String emUsername = args[1]; String emPassword = args[2]; String[] taskIds = new String[args.length - MIN_ARGS]; for (int i = 0; i < taskIds.length; i++) { taskIds[i] = args[i + MIN_ARGS]; } iControl.ManagementEMTaskStatus[] statuses = null; try { iControl.Interfaces ic = new iControl.Interfaces(); ic.initialize(emAddress, EM_PORT, emUsername, emPassword); statuses = ic.getManagementEM().get_task_status(taskIds); if (statuses.length != taskIds.length) { throw new Exception("wrong number of status values returned"); } } catch (Exception e) { System.err.println("Failed to get task status: " + e.getMessage()); System.exit(1); } for (int i = 0; i < taskIds.length; i++) { System.out.print("Task "); System.out.print(taskIds[i]); System.out.print(": "); System.out.println(statuses[i]); } } // public static void main } // public class ManagementEMGetTaskStatus310Views0likes0CommentsDiscover Device (Java code sample)
Problem this snippet solves: This Java client code sample uses Enterprise Manager's device inventory to discover a list of devices managed by the referenced Enterprise Manager. Code : /** * A class for testing the Management::EM::discover_devices iControl interface. */ public class ManagementEMDiscoverDevices { private static int MIN_ARGS = 3; private static int NUM_DEVICE_ARGS = 3; private static String USAGE = "ManagementEMDiscoverDevices " + "[ ] ..."; private static int EM_PORT = 443; /** * The main method. * * @param args command line arguments */ public static void main(String[] args) { if ((args.length < MIN_ARGS) || (((args.length - MIN_ARGS) % NUM_DEVICE_ARGS) != 0)) { System.err.println("Usage: " + USAGE); System.exit(1); } String emAddress = args[0]; String emUsername = args[1]; String emPassword = args[2]; int numDevices = (args.length - MIN_ARGS) / NUM_DEVICE_ARGS; String[] deviceAddresses = new String[numDevices]; String[] deviceUsernames = new String[numDevices]; String[] devicePasswords = new String[numDevices]; for (int i = 0; i < deviceAddresses.length; i++) { int index = MIN_ARGS + (i * NUM_DEVICE_ARGS); deviceAddresses[i] = args[index]; deviceUsernames[i] = args[index + 1]; devicePasswords[i] = args[index + 2]; } String taskId = null; try { iControl.Interfaces ic = new iControl.Interfaces(); ic.initialize(emAddress, EM_PORT, emUsername, emPassword); taskId = ic.getManagementEM().discover_devices(deviceAddresses, deviceUsernames, devicePasswords); } catch (Exception e) { System.err.println("Failed to discover devices: " + e.getMessage()); System.exit(1); } System.out.println("Discovery task started with task ID: " + taskId); } // public static void main } // public class ManagementEMDiscoverDevices294Views0likes0Commentsdelete_devices
Problem this snippet solves: Introduced: EM_v3.0 Use the delete_devices API to remove devices currently being managed by an Enterprise Manager. How to use this snippet: Prototype Python ic.Management.EM.deletedevices(deviceaddresses) C#, Java, and Perl ic.getManagementEM().delete_devices(deviceAddresses); Inputs Name Type Description IP addresses String Sequence This parameter specifies the IP addresses or hostnames of the F5 device(s) that you want to delete from the list of managed devices. Return values There is no explicit return when this API executes successfully. Exceptions The table lists error categories that Enterprise Manager can raise if the API call fails. Exception Name This exception is raised when... AccessDenied The credentials supplied by the client do not satisfy the F5 device's validation requirements. OperationFailed The API call causes an operation error. InvalidArgument The API call contains an invalid argument. Code : To view a code sample, click the relevant code type. C# (.net) Java Perl Python290Views0likes0CommentsJava Object Ltm Pool
Problem this snippet solves: This Java class will wrap the iControl LTM Pool interface to make it look like an object. This class is part of the "Java iControl Objects" series of Articles on DevCentral. This class creates a Pool object and allows a developer to interact with the iControl LTM Pool API methods in the context of using an object. Code : package iControl.Objects.LTM; public class Pool { private iControl.Interfaces _interfaces = null; private String _name = null; //----------------------------------------------------------------------- // Member Accessors //----------------------------------------------------------------------- public iControl.Interfaces getInterfaces() { return _interfaces; } public void setInterfaces(iControl.Interfaces interfaces) { _interfaces = interfaces; } public String getName() { return _name; } public void setName(String name) { _name = name; } //----------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------- public Pool(iControl.Interfaces interfaces, String name) { _interfaces = interfaces; _name = name; } protected void validateMembers() throws Exception { if ( (null == _interfaces) || (null == _name) ) { throw new Exception("Invalid Pool Parameters"); } } //----------------------------------------------------------------------- // Attribute Accessors //----------------------------------------------------------------------- // action_on_service_down public void setActionOnServiceDown(iControl.LocalLBServiceDownAction service_action) throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.LocalLBServiceDownAction [] action_list = { service_action }; _interfaces.getLocalLBPool().set_action_on_service_down(pool_names, action_list); } public iControl.LocalLBServiceDownAction getActionOnServiceDown() throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.LocalLBServiceDownAction [] action_list = _interfaces.getLocalLBPool().get_action_on_service_down(pool_names); return action_list[0]; } // active_member_count public long getActiveMemberCount() throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = _interfaces.getLocalLBPool().get_active_member_count(pool_names); return values[0]; } // aggregate_dynamic_ratio public long getAggregateDynamicRatio() throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = _interfaces.getLocalLBPool().get_aggregate_dynamic_ratio(pool_names); return values[0]; } // allow_nat_state public void setAllowNATState(iControl.CommonEnabledState state) throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.CommonEnabledState [] states = { state }; _interfaces.getLocalLBPool().set_allow_nat_state(pool_names, states); } public iControl.CommonEnabledState getAllowNATState() throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.CommonEnabledState [] states = _interfaces.getLocalLBPool().get_allow_nat_state(pool_names); return states[0]; } // allow_snat_state public void setAllowSNATState(iControl.CommonEnabledState state) throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.CommonEnabledState [] states = { state }; _interfaces.getLocalLBPool().set_allow_snat_state(pool_names, states); } public iControl.CommonEnabledState getAllowSNATState() throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.CommonEnabledState [] states = _interfaces.getLocalLBPool().get_allow_snat_state(pool_names); return states[0]; } // client_ip_tos public void setClientIPTos(long value) throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = { value }; _interfaces.getLocalLBPool().set_client_ip_tos(pool_names, values); } public long getClientIPTos() throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = _interfaces.getLocalLBPool().get_client_ip_tos(pool_names); return values[0]; } // client_link_qos public void setClientLinkQos(long value) throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = { value }; _interfaces.getLocalLBPool().set_client_link_qos(pool_names, values); } public long getClientLinkQos() throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = _interfaces.getLocalLBPool().get_client_link_qos(pool_names); return values[0]; } // gateway_failsafe_unit_id public void setGatewayFailsafeUnitId(long value) throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = { value }; _interfaces.getLocalLBPool().set_gateway_failsafe_unit_id(pool_names, values); } public long getGatewayFailsafeUnitId() throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = _interfaces.getLocalLBPool().get_gateway_failsafe_unit_id(pool_names); return values[0]; } // lb_method public void setLBMethod(iControl.LocalLBLBMethod lbMethod) throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.LocalLBLBMethod [] lb_methods = { lbMethod}; _interfaces.getLocalLBPool().set_lb_method(pool_names, lb_methods); } public iControl.LocalLBLBMethod getLBMethod() throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.LocalLBLBMethod [] lb_methods = _interfaces.getLocalLBPool().get_lb_method(pool_names); return lb_methods[0]; } // minimum_active_member public void setMinimumActiveMember(long value) throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = { value }; _interfaces.getLocalLBPool().set_minimum_active_member(pool_names, values); } public long getMinimumActiveMember() throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = _interfaces.getLocalLBPool().get_minimum_active_member(pool_names); return values[0]; } // minimum_up_member public void setMinimumUpMember(long value) throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = { value }; _interfaces.getLocalLBPool().set_minimum_up_member(pool_names, values); } public long getMinimumUpMember() throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = _interfaces.getLocalLBPool().get_minimum_up_member(pool_names); return values[0]; } // minimum_up_member_action public void setMinimumUpMemberAction(iControl.CommonHAAction action) throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.CommonHAAction [] actions = { action }; _interfaces.getLocalLBPool().set_minimum_up_member_action(pool_names, actions); } public iControl.CommonHAAction getMinimumUpMemberAction() throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.CommonHAAction [] actions = _interfaces.getLocalLBPool().get_minimum_up_member_action(pool_names); return actions[0]; } // minimum_up_member_enabled_state public void setMinimumUpMemberEnabledState(iControl.CommonEnabledState state) throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.CommonEnabledState [] states = { state }; _interfaces.getLocalLBPool().set_minimum_up_member_enabled_state(pool_names, states); } public iControl.CommonEnabledState getMinimumUpMemberEnabledState() throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.CommonEnabledState [] states = _interfaces.getLocalLBPool().get_minimum_up_member_enabled_state(pool_names); return states[0]; } // monitor_association public void setMonitorAssociation(iControl.LocalLBPoolMonitorAssociation association) throws Exception { validateMembers(); iControl.LocalLBPoolMonitorAssociation [] associations = { association }; _interfaces.getLocalLBPool().set_monitor_association(associations); } public iControl.LocalLBPoolMonitorAssociation getMonitorAssociation() throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.LocalLBPoolMonitorAssociation [] associations = _interfaces.getLocalLBPool().get_monitor_association(pool_names); return associations[0]; } public void removeMontitorAssociations() throws Exception { validateMembers(); String [] pool_names = { _name }; _interfaces.getLocalLBPool().remove_monitor_association(pool_names); } // server_ip_tos public void setServerIPTos(long value) throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = { value }; _interfaces.getLocalLBPool().set_server_ip_tos(pool_names, values); } public long getServerIPTos() throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = _interfaces.getLocalLBPool().get_server_ip_tos(pool_names); return values[0]; } // server_link_qos public void setServerLinkQOS(long value) throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = { value }; _interfaces.getLocalLBPool().set_server_link_qos(pool_names, values); } public long getServerLinkQOS() throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = _interfaces.getLocalLBPool().get_server_link_qos(pool_names); return values[0]; } // simple_timeout public void setSimpleTimeout(long value) throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = { value }; _interfaces.getLocalLBPool().set_simple_timeout(pool_names, values); } public long getSimpleTimeout() throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = _interfaces.getLocalLBPool().get_simple_timeout(pool_names); return values[0]; } // slow_ramp_time public void setSlowRampTime(long value) throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = { value }; _interfaces.getLocalLBPool().set_slow_ramp_time(pool_names, values); } public long getSlowRampTime() throws Exception { validateMembers(); String [] pool_names = { _name }; long [] values = _interfaces.getLocalLBPool().get_slow_ramp_time(pool_names); return values[0]; } //----------------------------------------------------------------------- // Public Methods //----------------------------------------------------------------------- public void create(iControl.LocalLBLBMethod lbMethod, iControl.CommonIPPortDefinition [] members) throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.LocalLBLBMethod [] lb_methods = { lbMethod }; iControl.CommonIPPortDefinition [][] membersAofA = { members }; _interfaces.getLocalLBPool().create(pool_names, lb_methods, membersAofA); } public void remove() throws Exception { validateMembers(); String [] pool_names = { _name }; _interfaces.getLocalLBPool().delete_pool(pool_names); } public void deletePersistenceRecords(iControl.LocalLBPersistenceMode mode) throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.LocalLBPersistenceMode [] modes = { mode }; _interfaces.getLocalLBPool().delete_persistence_record(pool_names, modes); } public iControl.CommonIPPortDefinition [] getMembers() throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.CommonIPPortDefinition [][] membersAofA = _interfaces.getLocalLBPool().get_member(pool_names); return membersAofA[0]; } public void addMember(iControl.CommonIPPortDefinition member) throws Exception { iControl.CommonIPPortDefinition [] memberA = { member }; addMembers(memberA); } public void addMembers(iControl.CommonIPPortDefinition [] members) throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.CommonIPPortDefinition [][] membersAofA = { members }; _interfaces.getLocalLBPool().add_member(pool_names, membersAofA); } public void removeMember(iControl.CommonIPPortDefinition member) throws Exception { iControl.CommonIPPortDefinition [] memberA = { member }; removeMembers(memberA); } public void removeMembers(iControl.CommonIPPortDefinition [] members) throws Exception { validateMembers(); String [] pool_names = { _name }; iControl.CommonIPPortDefinition [][] membersAofA = { members }; _interfaces.getLocalLBPool().remove_member(pool_names, membersAofA); } public iControl.CommonStatistic getStatistic(iControl.CommonStatisticType type) throws Exception { validateMembers(); iControl.CommonStatisticType [] types = { type }; iControl.CommonStatistic [] values = getStatistics(types); return values[0]; } public iControl.CommonStatistic [] getStatistics(iControl.CommonStatisticType [] types) throws Exception { validateMembers(); iControl.CommonStatistic [] values = null; String [] pool_list = { _name }; iControl.LocalLBPoolPoolStatistics stats = _interfaces.getLocalLBPool().get_statistics(pool_list); iControl.LocalLBPoolPoolStatisticEntry [] statsEntryA = stats.getStatistics(); iControl.LocalLBPoolPoolStatisticEntry statsEntry = statsEntryA[0]; iControl.CommonStatistic [] statsA = statsEntry.getStatistics(); if ( null == types ) { values = new iControl.CommonStatistic[statsA.length]; for(int i=0; i278Views0likes0CommentsJava Object Ltm Rule
Problem this snippet solves: This class is part of the "Java iControl Objects" series of Articles on DevCentral. This class creates an iRule object and allows a developer to interact with the iControl LTM Rule API methods in the context of using an object. Code : package iControl.Objects.LTM; public class iRule { private iControl.Interfaces _interfaces = null; private String _name = null; private String _definition = null; private Exception _lastException = null; //----------------------------------------------------------------------- // Member Accessors //----------------------------------------------------------------------- public iControl.Interfaces getInterfaces() { return _interfaces; } public void setInterfaces(iControl.Interfaces interfaces) { _interfaces = interfaces; } public String getName() { return _name; } public void setName(String value) { _name = value; } public String getDefinition() { return _definition; } public void setDefinition(String value) { _definition = value; } public Exception getLastException() { return _lastException; } //----------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------- public iRule(iControl.Interfaces interfaces, String name, String definition) { _interfaces = interfaces; _name = name; _definition = definition; } public iRule(iControl.Interfaces interfaces, iControl.LocalLBRuleRuleDefinition rule_def) { _interfaces = interfaces; _name = rule_def.getRule_name(); _definition = rule_def.getRule_definition(); } protected void validateMembers() throws Exception { if ( (null == _interfaces) || (null == _name) || (null == _definition) ) { throw new Exception("Invalid Rule Parameters"); } } protected void clearException() { _lastException = null; } //----------------------------------------------------------------------- // Attribute Accessors //----------------------------------------------------------------------- //----------------------------------------------------------------------- // Public Methods //----------------------------------------------------------------------- public boolean save() throws Exception { validateMembers(); clearException(); boolean bSaved = false; iControl.LocalLBRuleRuleDefinition ruleDef = new iControl.LocalLBRuleRuleDefinition(); ruleDef.setRule_name(_name); ruleDef.setRule_definition(_definition); iControl.LocalLBRuleRuleDefinition [] ruleDefA = { ruleDef }; // First attempt to create the iRule. try { _interfaces.getLocalLBRule().create(ruleDefA); bSaved = true; } catch(Exception ex) { if ( ex.getMessage().contains("already") ) { // If create fails due to it already existing, // then try to modify the existing one. try { _interfaces.getLocalLBRule().modify_rule(ruleDefA); bSaved = true; } catch(Exception ex2) { _lastException = ex2; } } else { _lastException = ex; } } return bSaved; } public boolean load() throws Exception { boolean bLoaded = false; validateMembers(); String [] rule_list = { _name }; try { iControl.LocalLBRuleRuleDefinition []ruleDef = _interfaces.getLocalLBRule().query_rule(rule_list); _definition = ruleDef[0].getRule_definition(); bLoaded = true; } catch(Exception ex) { _lastException = ex; } return bLoaded; } public boolean checkSyntax() throws Exception { clearException(); validateMembers(); boolean bValid = false; String tmpName = "icoTempRuleForStatusCheck"; iRule tmpiRule = new iRule(_interfaces, tmpName, _definition); try { if ( tmpiRule.save() ) { tmpiRule.delete(); bValid = true; } } catch(Exception ex) { _lastException = ex; bValid = false; } return bValid; } public void delete() throws Exception { validateMembers(); String [] rule_list = { _name }; _interfaces.getLocalLBRule().delete_rule(rule_list); } public iControl.LocalLBRuleRuleStatisticEntry getStatistics() throws Exception { validateMembers(); String [] rule_list = { _name }; iControl.LocalLBRuleRuleStatistics ruleStats = _interfaces.getLocalLBRule().get_statistics(rule_list); iControl.LocalLBRuleRuleStatisticEntry statsEntry = ruleStats.getStatistics()[0]; return statsEntry; } public void resetStatistics() throws Exception { validateMembers(); String [] rule_list = { _name }; _interfaces.getLocalLBRule().reset_statistics(rule_list); } //----------------------------------------------------------------------- // Public Static Methods //----------------------------------------------------------------------- public static iRule [] getList(iControl.Interfaces interfaces) throws Exception { iRule [] irule_list = null; iControl.LocalLBRuleRuleDefinition [] rule_defs = interfaces.getLocalLBRule().query_all_rules(); irule_list = new iRule[rule_defs.length]; for(int i=0; i277Views0likes0CommentsDelete Device (Java code sample)
Problem this snippet solves: This Java client code sample uses Enterprise Manager's device inventory to delete a list of devices managed by the referenced Enterprise Manager. Code : /** * A class for testing the Management::EM::delete_devices iControl interface. */ public class ManagementEMDeleteDevices { private static int MIN_ARGS = 3; private static String USAGE = "ManagementEMDeleteDevices " + "[ ] ..."; private static int EM_PORT = 443; /** * The main method. * * @param args command line arguments */ public static void main(String[] args) { if (args.length < MIN_ARGS) { System.err.println("Usage: " + USAGE); System.exit(1); } String emAddress = args[0]; String emUsername = args[1]; String emPassword = args[2]; String[] deviceAddresses = new String[args.length - MIN_ARGS]; for (int i = 0; i < deviceAddresses.length; i++) { deviceAddresses[i] = args[i + MIN_ARGS]; } try { iControl.Interfaces ic = new iControl.Interfaces(); ic.initialize(emAddress, EM_PORT, emUsername, emPassword); ic.getManagementEM().delete_devices(deviceAddresses); } catch (Exception e) { System.err.println("Failed to delete devices: " + e.getMessage()); System.exit(1); } System.out.println("Device(s) deleted"); } // public static void main } // public class ManagementEMDeleteDevices276Views0likes0Comments