java
17 Topicsdelete_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 Python289Views0likes0Commentsget_task_status
Problem this snippet solves: Introduced : EM_v3.0 Use the get_task_status API to determine the current status of a device discovery task. How to use this snippet: Python ic.Management.EM.get_task_status(ids = task_ids) C#, Java, and Perl ic.Management.EM.get_task_status(ids = task_ids); Inputs Name Type Description tasks String Sequence This parameter specifies the task IDs of the tasks for which you want to know the status. Return Values Name Type Description task TaskStatus Sequence The ID of the new discovery task. This ID can return the following values: TASK_STATUS_UNKNOWN TASK_STATUS_PENDING TASK_STATUS_STARTED TASK_STATUS_FAILED TASK_STATUS_COMPLETE TASK_STATUS_RUNNING TASK_STATUS_CANCELING TASK_STATUS_CANCELED TASK_STATUS_ABANDONED TASK_STATUS_TERMINATED TASK_STATUS_TIMED_OUT TASK_STATUS_RESCHEDULED Exceptions 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 Python269Views0likes0CommentsJava 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; i330Views0likes2CommentsJava 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); } } }346Views0likes1CommentGetting 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.0826Views0likes0CommentsJava 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) { } } }; } } }349Views0likes2CommentsGet 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 ManagementEMGetTaskStatus308Views0likes0CommentsJava Object System Service
Problem this snippet solves: This class is part of the "Java iControl Objects" series of Articles on DevCentral. This class creates a Service object and allows a developer to interact with the iControl System Services API methods in the context of using an object. Code : package iControl.Objects.System; public class Service { private iControl.Interfaces _interfaces = null; private iControl.SystemServicesServiceType _type = iControl.SystemServicesServiceType.SERVICE_UNKNOWN; //----------------------------------------------------------------------- // Member Accessors //----------------------------------------------------------------------- public iControl.Interfaces getInterfaces() { return _interfaces; } public void setInterfaces(iControl.Interfaces interfaces) { _interfaces = interfaces; } public iControl.SystemServicesServiceType getType() { return _type; } public void setType(iControl.SystemServicesServiceType type) { _type = type; } //----------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------- public Service(iControl.Interfaces interfaces, iControl.SystemServicesServiceType type) { _interfaces = interfaces; _type = type; } protected void validateMembers() throws Exception { if ( (null == _interfaces) || (null == _type) ) { throw new Exception("Invalid Service Parameters"); } } //----------------------------------------------------------------------- // Public Methods //----------------------------------------------------------------------- public void setAction(iControl.SystemServicesServiceAction action) throws Exception { validateMembers(); iControl.SystemServicesServiceType [] services = { _type }; _interfaces.getSystemServices().set_service(services, action); } public iControl.SystemServicesServiceStatusType getServiceStatus() throws Exception { validateMembers(); iControl.SystemServicesServiceType [] services = { _type }; iControl.SystemServicesServiceStatus [] statuses = _interfaces.getSystemServices().get_service_status(services); return statuses[0].getStatus(); } //----------------------------------------------------------------------- // Public Static Methods //----------------------------------------------------------------------- public static iControl.Objects.System.Service [] getServices(iControl.Interfaces interfaces) throws Exception { iControl.SystemServicesServiceType [] serviceTypes = interfaces.getSystemServices().get_list(); Service [] services = new Service[serviceTypes.length]; for(int i=0; i240Views0likes0CommentsJava Object Statistic Value
Problem this snippet solves: This Java class is a helper class for the Java Objects CodeShare entries. The StatisticValue class provides some assitance with the iControl Common__ULong64 class. Code : package iControl.Objects; public class StatisticValue extends iControl.CommonULong64 { static final long serialVersionUID = 1; public StatisticValue() { } public StatisticValue(iControl.CommonULong64 val) { setHigh(val.getHigh()); setLow(val.getLow()); } public StatisticValue(long high, long low) { setHigh(high); setLow(low); } public Double doubleValue() { long high = getHigh(); long low = getLow(); Double dVal = 0.0; Double rollOver = new Double((double)0x7fffffff); rollOver = new Double(rollOver.doubleValue() + 1.0); if ( high >= 0 ) { dVal = new Double((high << 32) & 0xffff0000); } else { dVal = new Double((high & 0x7fffffff) << 32) + (0x80000000 << 32); } if ( low >= 0 ) { dVal = new Double(dVal.doubleValue() + (double)low); } else { dVal = new Double(dVal.doubleValue() + (double)(low & 0x7fffffff) + rollOver.doubleValue()); } return dVal; } public String toString() { String dString = null; String size = ""; Double value = this.doubleValue(); Double dVal = value.doubleValue(); if ((dVal / 1024) >= 1.0) { size = "K"; dVal = dVal / 1024; } if ((dVal / 1024) >= 1.0) { size = "M"; dVal = dVal / 1024; } if ((dVal / 1024) >= 1.0) { size = "G"; dVal = dVal / 1024; } dString = new Double(dVal).toString(); dString = dString.substring(0, dString.indexOf(".") + 2) + size; return dString; } }228Views0likes0CommentsJava Object Networking Selfip
Problem this snippet solves: This Java class will wrap the iControl Networking::SelfIP 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 Networking::SelfIP object and allows a developer to interact with the iControl Networking::SelfIP API methods in the context of using an object. Code : package iControl.Objects.Networking; import iControl.Objects.System.Service; public class SelfIP { private iControl.Interfaces _interfaces = null; private String _address = null; private String _netmask = null; private iControl.CommonEnabledState _floating_state = null; private long _unit_id = -1; private String _vlan = null; //----------------------------------------------------------------------- // Member Accessors //----------------------------------------------------------------------- public iControl.Interfaces getInterfaces() { return _interfaces; } public void setInterfaces(iControl.Interfaces interfaces) { _interfaces = interfaces; } public String getAddress() { return _address; } public void setAddress(String address) { _address = address; } //----------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------- public SelfIP(iControl.Interfaces interfaces, String address) { _interfaces = interfaces; _address = address; } protected void validateMembers() throws Exception { if ( (null == _interfaces) || (null == _address) ) { throw new Exception("Invalid Pool Parameters"); } } //----------------------------------------------------------------------- // Attribute Accessors //----------------------------------------------------------------------- // floating_state public iControl.CommonEnabledState getFloatingState() throws Exception { if ( null == _floating_state ) { validateMembers(); String [] self_ips = { _address }; iControl.CommonEnabledState [] states = _interfaces.getNetworkingSelfIP().get_floating_state(self_ips); _floating_state = states[0]; } return _floating_state; } public void setFloatingState(iControl.CommonEnabledState state) throws Exception { validateMembers(); String [] self_ips = { _address }; iControl.CommonEnabledState [] states = { state }; _interfaces.getNetworkingSelfIP().set_floating_state(self_ips, states); _floating_state = state; } // netmask public String getNetmask() throws Exception { if ( null == _netmask ) { validateMembers(); String [] self_ips = { _address }; String [] netmasks = _interfaces.getNetworkingSelfIP().get_netmask(self_ips); _netmask = netmasks[0]; } return _netmask; } public void setNetmask(String netmask) throws Exception { validateMembers(); String [] self_ips = { _address }; String [] netmasks = { netmask}; _interfaces.getNetworkingSelfIP().set_netmask(self_ips, netmasks); _netmask = netmask; } // unit_id public long getUnitId() throws Exception { if ( -1 == _unit_id ) { validateMembers(); String [] self_ips = { _address }; long [] unit_ids = _interfaces.getNetworkingSelfIP().get_unit_id(self_ips); _unit_id = unit_ids[0]; } return _unit_id; } public void setUnitIdState(long unit_id) throws Exception { validateMembers(); String [] self_ips = { _address }; long [] unit_ids = { unit_id }; _interfaces.getNetworkingSelfIP().set_unit_id(self_ips, unit_ids); _unit_id = unit_id; } // vlan public String getVLAN() throws Exception { if ( null == _vlan ) { validateMembers(); String [] self_ips = { _address }; String [] vlans = _interfaces.getNetworkingSelfIP().get_vlan(self_ips); _vlan = vlans[0]; } return _vlan; } public void setVLAN(String vlan) throws Exception { validateMembers(); String [] self_ips = { _address }; String [] vlans= { vlan }; _interfaces.getNetworkingSelfIP().set_vlan(self_ips, vlans); _vlan = vlan; } //----------------------------------------------------------------------- // Public Methods //----------------------------------------------------------------------- public void create( String vlan, String netmask, long unit_id, iControl.CommonEnabledState state ) throws Exception { validateMembers(); String [] self_ips = { _address }; String [] vlan_names = { vlan }; String [] netmasks = { netmask }; long [] unit_ids = { unit_id }; iControl.CommonEnabledState [] states = { state }; _interfaces.getNetworkingSelfIP().create(self_ips, vlan_names, netmasks, unit_ids, states); _unit_id = unit_id; _netmask = netmask; _floating_state = state; _vlan = vlan; } public void remove() throws Exception { validateMembers(); String [] self_ips = { _address }; _interfaces.getNetworkingSelfIP().delete_self_ip(self_ips); } public void syncProperties() throws Exception { validateMembers(); getFloatingState(); getNetmask(); getUnitId(); getVLAN(); } //----------------------------------------------------------------------- // Public Static Methods //----------------------------------------------------------------------- public static SelfIP [] getList(iControl.Interfaces interfaces) throws Exception { SelfIP [] selfips = null; if ( null != interfaces ) { String [] selfip_list = interfaces.getNetworkingSelfIP().get_list(); selfips = new SelfIP[selfip_list.length]; for(int i=0; i245Views0likes0Comments