logo资料库

vmware vsphere java sdk java.doc

第1页 / 共53页
第2页 / 共53页
第3页 / 共53页
第4页 / 共53页
第5页 / 共53页
第6页 / 共53页
第7页 / 共53页
第8页 / 共53页
资料共53页,剩余部分请下载后查看
云平台 java-SDK-samples 工具使用说明 一、环境配置和脚本编译、执行 1.安装 java jdk-7u11-linux-x64.rpm,安装目录默认为/usr/java/jdk1.7.0_11 2.配置环境变量 [root@localhost samples]# vi /etc/profile export JAVAHOME="/usr/java/jdk1.7.0_11" export PATH="$JAVAHOME:$JAVAHOME/bin:$PATH" export CLASSPATH=".:$JAVAHOME/lib/tools.jar:$JAVAHOME/lib/dt.jar:/var/www/html/SDK/vsphere -ws/java/JAXWS/lib/vim25.jar:/var/www/html/SDK/vsphere-ws/java/JAXWS/lib/samples.jar" export a="--url https://192.168.28.253/sdk --username administrator --password micfc2013esx" 注意:红色部分为执行 java 脚本必须使用到的参数,可以定义成变量$a 3.脚本编译 [root@localhost samples]# pwd /var/www/html/SDK/vsphere-ws/java/JAXWS/samples [root@localhost samples]# javac com/vmware/general/Connect.java javac com/vmware/general/Connect.java 4.脚本执行 [root@localhost samples]# java com/vmware/general/Connect Expected --url, --username, --password arguments. This sample simply connects to an ESX server or to vCenter server Parameters: url username password [required] : url of the web service [required] : username for the authentication [required] : password for the authentication Command: run.bat com.vmware.general.Connect --url [webserviceurl] --username [username] --password [password] 出现以上帮助信息则脚本执行成功 注意:执行脚本时一定要写 java com/vmware/XX/XX,因为脚本需导入类 com.vmware.vim25. 二、具体脚本操作 1.创建分布式交换机 [root@localhost samples]# java com/vmware/host/DVSCreate
Expected --url, --username, --password arguments. [required]: url of the web service. [required]: username for the authentication [required]: password for the authentication [required]: "createdvs" for creating a new DVS OR "addportgroup" for Used to create/update Distributed Virtual Switch: url username Password option adding a port group to DVS dcname dvsname dvsdesc dvsversion numports portgroupname : Datacenter name [required]: Distributed Virtual Switch name [optional]: Description string of the switch : Distributed Virtual Switch either 4.0, 4.1.0, 5.0.0 or 5.1.0 : Number of ports in the portgroup. : Name of the port group. Create DVS : run.bat com.vmware.host.DVSCreate --url [URLString] --username [User] --password [Password] --option createdvs --dcname [dcname] --dvsname [dvsname] --dvsversion [dvsversion] Add PortGroup : run.bat com.vmware.host.DVSCreate --url [URLString] --username [User] --password [Password] --option --portgroupname [portgroupname] addportgroup [numports] --dvsname [dvsname] --numports 例如: 在名为 datacenter 的数据中心创建分布式交换机,名为 abcd,版本为 5.1.0 [root@localhost samples]# java com/vmware/host/DVSCreate $a --option createdvs --dcname datacenter --dvsname abcd --dvsversion 5.1.0 Success: Creating Distributed Virtual Switch 在名为 abcd 的分布式交换机上添加端口组,名为 abcd-pg1 端口数量为 256 [root@localhost --dvsname abcd --numports 256 --portgroupname abcd-pg1 Success: Adding Port Group com/vmware/host/DVSCreate $a samples]# java --option addportgroup
2.添加虚拟交换机 [root@localhost samples]# java com/vmware/host/AddVirtualSwitch $a --vswitchid abcd Expected --vswitchid, --hostname This sample is used to add a virtual switch Parameters: url username password vswitchid hostname [required] : url of the web service [required] : username for the authentication [required] : password for the authentication [required]: Name of the switch to be added [required]: Name of the host Command: Add a Virtual Switch run.bat com.vmware.host.AddVirtualSwitch --url [webserviceurl] --username [username] --password --vswitchid [mySwitch 例如:在主机名为 192.168.28.249 的主机上添加一个名为 abcd 的虚拟交换机 [root@localhost $a 192.168.28.249 --vswitchid abcd Successfully created vswitch : abcd com/vmware/host/AddVirtualSwitch [password] samples]# java --hostname
3.添加虚拟交换机端口组 [root@localhost samples]# java com/vmware/host/AddVirtualSwitchPortGroup Expected --url, --username, --password arguments. This sample is used to add a Virtual Machine Port Group to a vSwitch Parameters: url username password vswitchid portgroupname hostname [required] : url of the web service [required] : username for the authentication [required] : password for the authentication [required] : Name of the VSwitch to add portgroup to [required] : Name of the port group [required] : Name of the host Command: Add Virtual switch Port Group: run.bat com.vmware.host.AddVirtualSwitchPortGroup --url [webserviceurl] --username [username] --password --vswitchid [mySwitch] --portgroupname [myportgroup] --hostname [hostname] 例如:在主机 192.168.28.249 上的虚拟交换机 abcd 上添加一个名为 abcd-pg1 的端口组 [root@localhost samples]# java com/vmware/host/AddVirtualSwitchPortGroup $a --vswitchid abcd --portgroupname abcd-pg1 --hostname 192.168.28.249 Successfully created : abcd/abcd-pg1 [password] 4.添加虚拟网卡 [root@localhost samples]# java com/vmware/host/AddVirtualNic Expected --url, --username, --password arguments. This sample is used to add a Virtual Nic to a PortGroup on a VSwitch Parameters: url username password portgroupname ipaddress hostname datacentername [required] : url of the web service [required] : username for the authentication [required] : password for the authentication [required] : Name of the port group [optional] : ipaddress for the nic, if not set DHCP will be in affect for the nic [optional] : Name of the host [optional] : Name of the datacenter Command: Add VirtualNic to a PortGroup run.bat com.vmware.host.AddVirtualNic --url [webserviceurl]
[password] [password] --datacentername [mydatacenter] --username [username] --password --hostname [hostname] --portgroupname [myportgroup] --ipaddress [AAA.AAA.AAA.AAA] Add VirtualNic to a PortGroup on a Virtual Switch without hostname run.bat com.vmware.host.AddVirtualNic --url [webserviceurl] --username [username] --password --datacentername [mydatacenter] --portgroupname [myportgroup] --ipaddress [AAA.AAA.AAA.AAA] Add VirtualNic to a PortGroup on a Virtual Switch without datacentername run.bat com.vmware.host.AddVirtualNic --url [webserviceurl] --username [username] --password --portgroupname [myportgroup] --ipaddress [AAA.AAA.AAA.AAA] [password] 例如:在数据中心 datacenter 上的主机 192.168.28.249 的端口组 abcd-pg1 上添加一个虚拟网 卡 IP 地址为 10.10.10.1 [root@localhost samples]# java com/vmware/host/AddVirtualNic $a --hostname 192.168.28.249 --datacentername datacenter --portgroupname abcd-pg1 --ipaddress 10.10.10.1 Successful in creating nic : vmk1 with PortGroup :abcd-pg1 5.删除虚拟网卡 [root@localhost samples]# java com/vmware/host/RemoveVirtualNic Expected --url, --username, --password arguments. This sample removes a Virtual Nic from a PortGroup on a vSwitch Parameters: url username password portgroupname hostname datacentername [required] : url of the web service [required] : username for the authentication [required] : password for the authentication [required] : Name of port group to remove Virtual Nic from [required] : Name of host [optional] : Name of datacenter Command: Remove a VirtualNic from a PortGroup run.bat com.vmware.host.RemoveVirtualNic --url [webserviceurl] --username [username] --password --portgroupname [myportgroup] --hostname [hostname] Remove a VirtualNic from a PortGroup without hostname run.bat com.vmware.host.RemoveVirtualNic --url [webserviceurl] --username [username] --password [password] --datacentername [mydatacenter] [password] --datacentername [mydatacenter]
--portgroupname [myportgroup] Remove a VirtualNic from a PortGroup without datacentername run.bat com.vmware.host.RemoveVirtualNic --url [webserviceurl] --username [username] --password --portgroupname [myportgroup] --hostname [name of the host] [password] 例如:从数据中心 datacenter 上的主机 192.168.28.249 上的端口组为 abcd-pg1 的上面移除虚 拟网卡 [root@localhost datacenter --hostname 192.168.28.249 --portgroupname abcd-pg1 Successfully removed virtual nic from portgroup : abcd-pg1 com/vmware/host/RemoveVirtualNic $a samples]# java --datacentername 6.删除虚拟交换机端口组 [root@localhost samples]# java com/vmware/host/RemoveVirtualSwitchPortGroup Expected --url, --username, --password arguments. This sample removes a Virtual Switch PortGroup Parameters: url username password portgroupname hostname [required] : url of the web service [required] : username for the authentication [required] : password for the authentication [required] : Name of the port group to be removed [required] : Name of the host Command: Remove Virtual Switch Port Group run.bat com.vmware.host.RemoveVirtualSwitchPortGroup --url [webserviceurl] --username [username] --password [password] --portgroupname[myportgroup] --hostname [hostname] 例如:从主机 192.168.28.249 上移除端口组 abcd-pg1 [root@localhost samples]# java com/vmware/host/RemoveVirtualSwitchPortGroup $a --hostname 192.168.28.249 --portgroupname abcd-pg1 Successfully removed portgroup abcd-pg1
7.删除虚拟交换机 [root@localhost samples]# java com/vmware/host/RemoveVirtualSwitch Expected --url, --username, --password arguments. This sample removes a virtual switch Parameters: url username password vswitchid hostname [required] : url of the web service [required] : username for the authentication [required] : password for the authentication [required] : Name of the switch to be added [required] : Name of the host Command: Remove a Virtual Switch run.bat com.vmware.host.RemoveVirtualSwitch --url [webserviceurl] --username [username] --password [password] --vswitchid [mySwitch] --hostname [hostname] 例如:从主机 192.168.28.249 上移除名为 abcd 的虚拟交换机 [root@localhost 192.168.28.249 --vswitchid abcd : Successful removing : abcd samples]# java com/vmware/host/RemoveVirtualSwitch $a --hostname 8.显示 SCSILUN 信息 [root@localhost samples]# java com/vmware/scsilun/SCSILunName --hostname 192.168.28.249 This sample displays the CanonicalName,Vendor,Model,Data,Namespace and NamespaceId of the host SCSI LUN name Parameters: url username password hostname [required] : url of the web service. [required] : username for the authentication [required] : password for the authentication [required] : host for which SCSI details will be displayed Command: run.bat com.vmware.scsilun.SCSILunName --url [webserviceurl] --username [username] --password [password] --hostname [host name] 例如:查看主机 192.168.28.249 的 SCSILUN 信息 [root@localhost 192.168.28.249 samples]# java com/vmware/scsilun/SCSILunName $a --hostname SCSI LUN 1
-------------- Data Canonical Name Namespace Namespace ID : 1 3 0 16 96 6 5 -80 5 -101 -97 64 25 -17 -61 124 34 -11 -116 47 : naa.600605b0059b9f4019efc37c22f58c2f : NAA : 3 VMFS Affected None Virtual Machines None 9.将虚拟机导出为 OVF 模板 [root@localhost samples]# java com/vmware/vapp/OVFManagerExportVMDK Expected --url, --username, --password arguments. This is a demostrates OVFManager.Exports VMDK's of a VM to the localSystem. url username password vmname host localPath run.bat com.vmware.vapp.OVFManagerExportVMDK --url [webserviceurl] --username [username] --password [password]--vmname [VM name] --host [Name of Host] --localPath [path of local System] [required] : url of the web service. [required] : username for the authentication [required] : password for the authentication [required] : Name of the virtual machine [required] : Name of Host System [required] : Absolute path of localSystem folder 例如:将主机 192.168.28.249 上虚拟机 abcd 导出到本地/root 下 [root@localhost samples]# java com/vmware/vapp/OVFManagerExportVMDK $a --vmname abcd --host 192.168.28.249 --localPath /root Getting the HTTP NFCLEASE for the VM: abcd HttpNfcLeaseState: READY ######################################################## HttpNfcLeaseInfo Lease Timeout: 300000000 Total Disk capacity: 31457280 HttpNfcLeaseDeviceUrl : 1 Device URL Import Key: Device URL Key: /vm-73/VirtualLsiLogicController0:0 Device URL : https://192.168.28.249/nfc/52764320-b48e-ae71-4275-43ecd4f72f26/disk-0.vmdk Updated device URL: https://192.168.28.249/nfc/52764320-b48e-ae71-4275-43ecd4f72f26/disk-0.vmdk SSL Thumbprint : 37:1B:58:31:2E:48:44:31:EC:88:DE:92:95:DC:60:99:18:DE:36:21 ########################################################
分享到:
收藏