java - vsphere-automation-sdk-java 未经身份验证-vSphere 6.5
问题描述
我正在尝试使用 Java SDK ( https://github.com/vmware/vsphere-automation-sdk-java ) 克隆一个 vsphere VM,我能够运行所有可用的示例,例如 list VM 和 creat VM 等等。但是当我尝试执行vmService.instantClone(instantCloneSpec)
它时会遇到这个特定的错误。
代码:
import java.util.Collections;
import java.util.List;
import com.vmware.vcenter.VMTypes;
import org.apache.commons.cli.Option;
import com.vmware.vcenter.VM;
import org.camunda.bpm.getstarted.loanapproval.common.SamplesAbstractBase;
public class CloneVmManager extends SamplesAbstractBase {
private VM vmService;
/**
* Define the options specific to this sample and configure the sample using
* command-line arguments or a config file
*
* @param args command line arguments passed to the sample
*/
protected void parseArgs(String[] args) {
List<Option> optionList = Collections.<Option>emptyList();
super.parseArgs(optionList, args);
}
protected void setup() throws Exception {
this.vmService =
vapiAuthHelper.getStubFactory()
.createStub(VM.class, sessionStubConfig);
}
protected void run() throws Exception {
// TODO: Add your sample code here
try {
VMTypes.InstantClonePlacementSpec placementSpec= new VMTypes.InstantClonePlacementSpec();
placementSpec.setDatastore("datastore1");
placementSpec.setFolder("cvs");
VMTypes.InstantCloneSpec instantCloneSpec =new VMTypes.InstantCloneSpec();
instantCloneSpec.setName("instantClone1");
// instantCloneSpec.setSource("tpl_reproxy-6_10-wax-CentOS6-h9-ver2.4");
instantCloneSpec.setSource("_Ubuntu_19_Template");
instantCloneSpec.setDisconnectAllNics(true);
instantCloneSpec.setPlacement(placementSpec);
vmService.instantClone(instantCloneSpec);
}catch (Exception e){
System.out.println("something went wrong"+e.getMessage());
e.printStackTrace();
}
}
protected void cleanup() throws Exception {
// TODO: Add cleanup here
}
public static void main(String[] args) throws Exception {
/*
* Execute the sample using the command line arguments or parameters
* from the configuration file. This executes the following steps:
* 1. Parse the arguments required by the sample
* 2. Login to the server
* 3. Setup any resources required by the sample run
* 4. Run the sample
* 5. Cleanup any data created by the sample run, if cleanup=true
* 6. Logout of the server
*/
// new CloneVmManager().execute(args);
}
public void runcustom(String[] args) throws Exception{
System.out.println("inside clone vm");
for(String s:args){
System.out.println("arg:->"+s);
}
new CloneVmManager().execute(args);
}
}
正如您所看到的,您很容易受到中间人攻击,因为我提供了--skip-server-verification
arg,所以不确定这是身份验证问题。
我的参数就像:
String arg[] = {
"--server","192.168.1.1","--username","administrator@vsphere.local","--password","password","--skip-server-verification"}
错误:
2019-12-10 11:06:33.685 WARN 1140 --- [nio-8080-exec-3] c.v.v.i.p.c.r.h.TrustAllX509TrustManager : Skipped the validation of a certificate chain due to configuration policy. Your co
nnection is not secure!
2019-12-10 11:06:33.729 WARN 1140 --- [nio-8080-exec-3] c.v.v.i.p.c.r.h.AllowAllHostnameVerifier : Cannot validate the identity of 192.168.1.160 due to the hostname-verification bei
ng disabled. You are susceptible to man-in-the-middle attacks!
something went wrongUnauthenticated (com.vmware.vapi.std.errors.unauthenticated) => {
messages = [LocalizableMessage (com.vmware.vapi.std.localizable_message) => {
id = vapi.method.authentication.required,
defaultMessage = This method requires authentication.,
args = [],
params = <null>,
localized = <null>
}],
data = <null>,
errorType = UNAUTHENTICATED,
challenge = <null>
}
com.vmware.vapi.std.errors.Unauthenticated: Unauthenticated (com.vmware.vapi.std.errors.unauthenticated) => {
messages = [LocalizableMessage (com.vmware.vapi.std.localizable_message) => {
id = vapi.method.authentication.required,
defaultMessage = This method requires authentication.,
args = [],
params = <null>,
localized = <null>
}],
data = <null>,
errorType = UNAUTHENTICATED,
challenge = <null>
}
at com.vmware.vapi.std.errors.Unauthenticated._newInstance2(Unauthenticated.java:244)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
解决方案
VM#instantClone API 在 vSphere 6.5 中不可用。即使在 6.7 或最新的 6.7 U3 中也不可用。它目前仅在 AWS 上的 VMC 中可用。
“此方法已添加到 vSphere API 6.7.1 中。” 参考文档中的声明(参考 6.7 U1)是错误的。
推荐阅读
- excel - 使用 Vlookup + count if 公式获取数据
- javascript - p5.js WebGL 3d 图形在旋转时被 2d 背景覆盖
- python - 安排训练和测试机器学习
- spring-boot - 带有 keycloak 的 Spring Cloud 微服务
- ios - [<__NSCFString 0x600003802460> valueForUndefinedKey:]: 这个类对使用 FEMMApping 的键的键值编码不兼容 映射中的问题
- python - 循环添加更多输入
- java - 检查是否在 Android 中启用了振铃模式的振动
- javascript - 为什么这段 JavaScript 和 WebRTC 代码不起作用?
- ios - 如何以圆形方式检测面部的运动..我正在使用 AVFoundation 拍摄面部的多个快照
- android - 如何像图像一样将数字添加到底部栏