解决了

UEFI VM创建

  • 2021年2月11日
  • 6个答复
  • 282意见

  • CMH
  • 资源管理器
  • 0答复

大家好,

我创建了这个伟大的PowerShell脚本,使VM在AHV中。这是一段旅程,让我告诉你,但我做到了。我想添加的一件事是使用UEFI引导选项创建VM。我知道这需要在Creation时完成,我可以在ACLI中使用以下内容来创建它:

acli vm.create uefivm2 uefi_boot = true

然而;有没有办法使用PowerShell?我将考虑找到上面的SSH命令的方法

有什么方法可以使用PowerShell使用UEFI创建VM?

谢谢,

斯科特

图标

最好的答案斯基特2021年2月18日,23:12

I got this to work. Here is the code so if someone like me comes along they do not have to reinvent the wheel.<\/p>

add-type @\"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
\u00a0 \u00a0 public bool CheckValidationResult(
\u00a0 \u00a0 ServicePoint srvPoint, X509Certificate certificate,
\u00a0 \u00a0 WebRequest request, int certificateProblem) {
\u00a0 \u00a0 \u00a0 \u00a0 return true;
\u00a0 \u00a0 }
}
\"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$password = Read-Host -AsSecureString -Prompt \"Password\"
$NTNXCred = New-Object System.Management.Automation.PsCredential(\"Username\",$password)
$RESTAPIUser = $NTNXCred.UserName
$RESTAPIPassword = $NTNXCred.GetNetworkCredential().Password
$Header = @{
\"Authorization\" = \"Basic \"+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($RESTAPIUser+\":\"+$RESTAPIPassword ))}<\/p>

$Header.Add(\"content-type\", \"application\/json\")<\/p>

$response = Invoke-WebRequest -Uri 'https:\/\/CVMIP:9440\/PrismGateway\/services\/rest\/v2.0\/vms\/' -Method POST -Headers $Header -ContentType 'application\/json' -Body '{\"allow_live_migrate\":true,\"boot\":{\"secure_boot\":true,\"uefi_boot\":true},\"name\":\"UEFITest\",\"memory_mb\":2048,\"num_vcpus\":2}' -UseBasicParsing
\u00a0<\/p>","className":"post__content__best_answer"}">

查看原件

该主题已关闭以供评论

6个答复

UserLevel 6
徽章 +5

嗨,CMH,

肯定这是一项成就!
我看不到任何指出的PowerShell CMDLET参考。我认为我有一个想法是,如果API允许,您可以创建自定义CMDLET。我建议查看Prism Element(Gear Icon下拉)中的REST API,因为它会给您一些东西。查看v2/vms/post。

徽章 +1

因此,我使用REST API构建了UEFI VM。我在此页面上制作了以下代码:

https://www.nutanix.dev/reference/prism_element/v2/api/vms/post-vms-createvm/

$ headers =@{}
$ headers.add(“ content-type”,“ application/json”)
$ wenspy = invoke -webrequest -uri'https:// cvmip:9440/prismgateway/services/services/rest/v2.0/vms/vms/'-method post -headers $ headers $ headers -contenttype'application'application'application'application/json'' -“:true,“ boot”:{“ secure_boot”:true,“ uefi_boot”:true},“ name”:“ uefitest”,“ memory_mb”:2048,“ num_vcpus”:2}'-credential $ ntnxcreden

我目前正在遇到以下错误:

远程服务器返回错误:(401)未经授权。

在API资源管理器中,我的代码工作。上面的代码没有。我在两种情况下都使用相同的帐户。我还有其他东西吗?

谢谢,

斯科特

UserLevel 6
徽章 +5

嗨,斯科特,

这在Nutanix开发页面中起作用。它在哪里不起作用?REST API Explorer?

徽章 +1

我使用Nutanix开发页面来构建JSON代码。然后,我使用REST API Explorer测试代码并确认其工作。然后,我使用了上面的代码,因为它只是将JSON包装在PowerShell中,因此我可以用脚本称呼它,这就是失败的。我假设REST API进行身份验证正在发生一些额外的呼叫,但我还没有弄清楚这部分。

徽章 +1

我让这个工作。这是代码,因此,如果像我这样的人来了,他们不必重新发明轮子。

add-type @”
使用system.net;
使用system.security.cryptography.x509certificates;
公共类Trust Allcertspolicy:IcertificatePolicy {
公共bool checkValidationResult(
ServicePoint SRVPoint,X509Certificate证书,
WebRequest请求,INT证书问题){
返回true;
}
}
“@
[system.net.servicepointManager] :: certiferpolicy = new-object trustAllCertSpolicy
[net.ServicePointManager] :: SecurityProtocol = [net.securityprotocoltype] :: TLS12
$ password = read -host -securestring- prompt“密码”
美元
$ RESTAPIUSER = $ ntnxcred.username
$ RESTAPIPASSWord = $ ntnxcred.getNetworkcredential()。密码
$ header = @{
“授权” =“ basic”+[system.convert] :: tobase64String([System.text.Encoding] :: utf8.getBytes($ restapiuser+“:”+$ restapipAssword)}})}

$ header.add(“ content-type”,“ application/json”)

$ wendesp = invoke -webrequest -uri'https:// cvmip:9440/prismgateway/services/services/rest/v2.0/vms/vms/'-method post -headers $ headers $ header -contenttype'application'application/json'application/json'' -“:true,“ boot”:{“ secure_boot”:true,“ uefi_boot”:true},“ name”:“ uefitest”,“ memory_mb”:2048,“ num_vcpus”:2}'-UseBasicParsing

UserLevel 6
徽章 +5

嗨,Skeeter,

很高兴您使它起作用。感谢您分享最终结果。

Learn more about our cookies.<\/a>","cookiepolicy.button":"Accept cookies","cookiepolicy.button.deny":"Deny all","cookiepolicy.link":"Cookie settings","cookiepolicy.modal.title":"Cookie settings","cookiepolicy.modal.content":"We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.<\/a>","cookiepolicy.modal.level1":"Basic
Functional","cookiepolicy.modal.level2":"Normal
Functional + analytics","cookiepolicy.modal.level3":"Complete
Functional + analytics + social media + embedded videos"}}}">
Baidu