archive/v1/client/findByName.js
function findByName(args) {
		
		// validate the types
		if (!args.type || !_.includes(['Datastore', 'HostSystem', 'Network', 'VirtualMachine'], args.type)) {
			return new Promise(function(resolve, reject) {
				reject({
					errorCode: 400,
					message: 'Invalid search type. Valid types are Datastore, HostSystem, Network, and VirtualMachine'
				});
			});
		}
		
		// start the search
		return findByNameEx(args).then(function(matches) {

			// if no matches return an empty array
			if (!matches || (Array.isArray(matches) && matches.length === 0)) {
				return [];
			}
			
			// check for an ID only response and format the matches as an array of objects
			else if (Array.isArray(args.properties) && (args.properties.length === 0 || args.properties[0] === 'id')) {
				return _.map(matches, function(id) {
					return {id: id};
				});
			}
			
			// otherwise add get the items with their properties
			return _client.retrieve({
				type: args.type,
				id: matches,
				properties: args.properties
			});
		});
	}
function findByName(args) {
		
		// validate the types
		if (!args.type || !_.includes(['Datastore', 'HostSystem', 'Network', 'VirtualMachine'], args.type)) {
			return new Promise(function(resolve, reject) {
				reject({
					errorCode: 400,
					message: 'Invalid search type. Valid types are Datastore, HostSystem, Network, and VirtualMachine'
				});
			});
		}
		
		// start the search
		return findByNameEx(args).then(function(matches) {

			// if no matches return an empty array
			if (!matches || (Array.isArray(matches) && matches.length === 0)) {
				return [];
			}
			
			// check for an ID only response and format the matches as an array of objects
			else if (Array.isArray(args.properties) && (args.properties.length === 0 || args.properties[0] === 'id')) {
				return _.map(matches, function(id) {
					return {id: id};
				});
			}
			
			// otherwise add get the items with their properties
			return _client.retrieve({
				type: args.type,
				id: matches,
				properties: args.properties
			});
		});
	}
function findByName ( args ) { // validate the types if ( ! args . type || ! _ . includes ( [ 'Datastore' , 'HostSystem' , 'Network' , 'VirtualMachine' ] , args . type ) ) { return new Promise ( function ( resolve , reject ) { reject ( { errorCode : 400 , message : 'Invalid search type. Valid types are Datastore, HostSystem, Network, and VirtualMachine' } ) ; } ) ; } // start the search return findByNameEx ( args ) . then ( function ( matches ) { // if no matches return an empty array if ( ! matches || ( Array . isArray ( matches ) && matches . length === 0 ) ) { return [ ] ; } // check for an ID only response and format the matches as an array of objects else if ( Array . isArray ( args . properties ) && ( args . properties . length === 0 || args . properties [ 0 ] === 'id' ) ) { return _ . map ( matches , function ( id ) { return { id : id } ; } ) ; } // otherwise add get the items with their properties return _client . retrieve ( { type : args . type , id : matches , properties : args . properties } ) ; } ) ; }
finds entities by name
@param {Object} args - Arguments hash
@param {string} args.type - Type of entity to search for
@param {(string|string[])} args.name - Name or names to search for
@param {(Object|Object[])} [args.parent] - Parent entity or array of parent enties to search from
@param {string} [args.parent.type] - Parent type
@param {string} [args.parent.id] - Parent id
@param {boolean} [recursive=false] - Recursively search the parent
@param {number} [limit=1] - Limit results
finds entities by name