All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vmware.vim25.mo.samples.LicenseUtil Maven / Gradle / Ivy

The newest version!
/*================================================================================
Copyright (c) 2008 VMware, Inc. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution.

* Neither the name of VMware, Inc. nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior 
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
================================================================================*/

package com.vmware.vim25.mo.samples;

import java.net.URL;
import java.rmi.RemoteException;

import com.vmware.vim25.*;
import com.vmware.vim25.mo.*;
import com.vmware.vim25.mo.util.*;

 /**
 *
 *Demonstrates uses of the Licensing API using License Managed Object
 *Reference.
 * 
 *To run this samples following parameters are used :
 *
 *action     [required]   : action to be performed [browse|setserver|setedition|featureinfo]
 *serverurl  [optional]   : url of license server
 *edition    [optional]   : Licensed edition 
 *feature    [optional]   : Licensed feature  
 *
 * @author sjin
 *
*/ public class LicenseUtil { public static void main(String[] args) throws Exception { CommandLineParser clp = new CommandLineParser(constructOptions(), args); String urlStr = clp.get_option("url"); String username = clp.get_option("username"); String password = clp.get_option("password"); String action = clp.get_option("action"); String serverurl = clp.get_option("serverurl"); String edition = clp.get_option("edition"); String feature = clp.get_option("feature"); if(!customValidation(clp)) return; ServiceInstance si = new ServiceInstance(new URL(urlStr), username, password, true); LicenseManager licMgr = si.getLicenseManager(); if(licMgr==null) { System.out.println("There is NO LicMgr available..."); return; } if(action.equalsIgnoreCase("browse")) { System.out.println("Display the license usage. The license usage is a list of supported features" + "and the number of licenses that have been reserved."); displayLicenseUsage(licMgr); } else if(action.equalsIgnoreCase("setserver")) { System.out.println("Set the License server."); setLicenseServer(licMgr,serverurl); } else if(action.equalsIgnoreCase("setedition")) { System.out.println("Set the License Edition."); setEdition(licMgr, edition); } else if(action.equalsIgnoreCase("featureinfo")) { displayFeatureInfo(licMgr, feature); } else { System.out.println("Invalid Action "); System.out.println("Valid Actions [browse|setserver|setedition|featureinfo]"); } } private static void displayLicenseUsage(LicenseManager licMgr) throws Exception { LicenseUsageInfo licUsage = licMgr.queryLicenseUsage(null); LicenseAvailabilityInfo[] avail = licMgr.queryLicenseSourceAvailability(null); System.out.println("==========Usage=========="); print(licUsage); System.out.println("==========Available=========="); print(avail); } private static void setLicenseServer(LicenseManager licMgr, String serverurl) throws Exception { LicenseServerSource source = new LicenseServerSource(); source.setLicenseServer("serverurl"); try { licMgr.configureLicenseSource(null, source); } catch(RemoteException re) { re.printStackTrace(); } } private static void setEdition(LicenseManager licMgr, String edition) throws Exception { boolean valid = validate(edition); if(valid) { try { licMgr.setLicenseEdition(null, edition); } catch(RemoteException re) { re.printStackTrace(); } } } private static void displayFeatureInfo(LicenseManager licMgr, String featureName) throws Exception { LicenseFeatureInfo [] feature = licMgr.getFeatureInfo(); for(int i=0 ;i < feature.length; i++) { if(feature[i].getKey().equalsIgnoreCase(featureName)) { System.out.println("Name " + feature[i].getFeatureName()); System.out.println("Unique Key " + feature[i].getKey()); System.out.println("State " + feature[i].getState()); System.out.println("Cost Unit " + feature[i].getCostUnit()); return; } } System.out.println("Feature Not Available"); } private static boolean validate(String feature) { String [] features = {"backup","das","drs","esxExpress","esxFull" ,"esxHost","esxVmtn","gsxHost","iscsi","nas", "san","vc","vmotion","vsmp"}; boolean flag = false; for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy