[root@master ~]# cat simple_flow.pl ! /usr/bin/perl -w use strict; use warnings; 导入 vSphere SDK for Perl 的运行支持模块 此模块用来完成服务器端 - 客户端数据映射、载入客户端和服务器端之间的交互函数等 use VMware::VIRuntime; hash 结构 %opts 存放自定义命令行参数 my %opts =( entity => { type => “=s”, variable => “VI_ENTITY”, help => “ManagedEntity type: HostSystem, etc”, required => 1, }, ); vSphere SDK for Perl 为所有脚本提供了一些基本的命令行参数,如 –server,–url 等 Opts::add_options 方法用以添加用户自定义参数 Opts::add_options(%opts); 解析命令行参数 Opts::parse(); 验证命令行参数 Opts::validate(); 连接远程服务器,vCenter 或 ESX server Util::connect(); 提取命令行参数 entity 的值 my $entity_type = Opts::get_option(‘entity’); 根据 entity 值查询服务器端对象, Vim::find_entity_views 返回服务器端对象对应的 Perl 视图 my entityviews=Vim::findentityviews(viewtype=>entity_type); 输出服务器端对象 Perl 视图的信息,如类型和名称等 foreach my entityview(@entity_views) { my entityname=entity_view->name; Util::trace(0, “Found entitytype:entity_name ”); } 断开与远程服务器的连接 Util::disconnect(); [root@master ~]# perl simple_flow.pl –server 192.168.32.8 –username root –password 1234567 –entity VirtualMachine Found VirtualMachine: dr-mysql01—192.168.32.101-贡文 Found VirtualMachine: v-test-web02-192.168.32.214 Found VirtualMachine: v-test-app01-192.168.32.215 Found VirtualMachine: v-test-app02-192.168.32.216 Found VirtualMachine: v-dev-migdb01-192.168.32.21 Found VirtualMachine: test-oadb01-192.168.32.32 Found VirtualMachine: v-test-db02-192.168.32.232 Found VirtualMachine: demo-disk10G-mem512M-192.168.32.150 Found VirtualMachine: v-test-nfs01-192.168.32.219 Found VirtualMachine: HZ-TEST-02-192.168.32.10 Found VirtualMachine: v-test-db03-192.168.32.233 Found VirtualMachine: v-test-redis01-192.168.32.217 Found VirtualMachine: v-test-mgr01-192.168.32.235 Found VirtualMachine: v-dev-db01-192.168.32.14 Found VirtualMachine: v-dev-redis01-192.168.32.15 Found VirtualMachine: v-dev-redis02-192.168.32.16(image-ftp) Found VirtualMachine: v-lhb-prx01-192.168.32.111 Found VirtualMachine: HZ-TEST-192.168.32.9-尚晓斌-MySQL Found VirtualMachine: v-lhb-mgr01-192.168.32.114 Found VirtualMachine: v-lhb-nfs01-192.168.32.115 Found VirtualMachine: v-lhb-db03-192.168.32.119 Found VirtualMachine: v-test-mysql-192.168.32.6 Found VirtualMachine: v-test-redis-192.168.32.167 Found VirtualMachine: v-test-redis-192.168.32.168 Found VirtualMachine: v-test-tomcat-192.168.32.169-pay Found VirtualMachine: v-test-tomcat-192.168.32.170-api Found VirtualMachine: HZ-TEST-192.168.32.12-尚晓斌-TOMCAT Found VirtualMachine: v-test-tomcat-192.168.32.171-flow Found VirtualMachine: v-test-nginx-192.168.32.172 Found VirtualMachine: v-test-haproxy-192.168.32.173 Found VirtualMachine: v-test-mysql-pay-192.168.32.5 Found VirtualMachine: v-pro-运维堡垒机-192.168.32.177 Found VirtualMachine: v-test-nginx-192.168.32.174-back_office Found VirtualMachine: v-test-192.168.32.175-redis01 Found VirtualMachine: v-test-192.168.32.176-redis02 Found VirtualMachine: v-test-proxy-192.168.32.178 Found VirtualMachine: v-test-backoffice-192.168.32.180 Found VirtualMachine: test01-192.168.32.11- 张安挺 Found VirtualMachine: v-test-zjzc-mysql-192.168.32.185 Found VirtualMachine: v-test-redis-192.168.32.187 Found VirtualMachine: v-test-app192.168.32.181 Found VirtualMachine: v-test-文件服务器-192.168.32.182 Found VirtualMachine: v-test-pay-mysql-192.168.32.186 Found VirtualMachine: 客服堡垒机-192.168.32.188 Found VirtualMachine: mysql-slave-192.168.32.116 Found VirtualMachine: 生产slave-192.168.32.118 Found VirtualMachine: slave-pay-192.168.32.146 Found VirtualMachine: check-zjzc-192.168.32.218 Found VirtualMachine: test-image01-192.168.32.102-尚晓斌(sftp) Found VirtualMachine: v-pro-192.168.32.55-zabbix Found VirtualMachine: v-test-prx01-192.168.32.211 Found VirtualMachine: v-test-prx02-192.168.32.212 Found VirtualMachine: v-test-web01-192.168.32.213