Join us for a virtual Nutanix User Group meeting with Jarian Gibson as he covers Nutanix Cloud Clusters (NC2) on Azure and AWS with Citrix. <\/span><\/p>

Jarian will take a deep dive into NC2 on Azure architecture and Citrix on NC2 on Azure\u00a0that helps you strengthen your business continuity and disaster recovery position. He\u2019ll also provide the latest updates for NC2 on AWS.<\/span><\/p>

Plus, we're\u00a0giving away a Nutanix suitcase to one lucky winner!\u00a0Opt-in when you register\u00a0to be entered to win.\u00a0<\/p>","author":{"id":113632,"url":"\/members\/karlie-beil-113632","name":"Karlie Beil","avatar":"https:\/\/uploads-us-west-2.insided.com\/nutanix-us\/icon\/200x200\/1581aab3-bcf6-49f4-b2fb-3d11e8c010dc.png","userTitle":"Community Manager","rank":{"isBold":false,"isItalic":false,"isUnderline":false,"name":"Community Manager","color":"#0873ba"},"userLevel":4},"type":"Webinar","url":"https:\/\/next.nutanix.com\/events\/global-nug-nc2-on-azure-and-aws-with-citrix-151","image":"https:\/\/uploads-us-west-2.insided.com\/nutanix-us\/attachment\/f9693b5b-436b-427a-9b98-531b4040ff24_thumb.png","location":"","startsAt":1678298400,"endsAt":1678302000,"contentType":"event","attendees":[],"attendeeCount":0,"isLoggedInUserAttendee":false,"createdAt":"1675974969"},"phrases":{"Forum":{"{n} year|{n} years":"{n} year|{n} years","{n} month|{n} months":"{n} month|{n} months","{n} day|{n} days":"{n} day|{n} days","{n} hour|{n} hours":"{n} hour|{n} hours","{n} minute|{n} minutes":"{n} minute|{n} minutes","just":"just now","{plural} ago":"{plural} ago"}}}">

解决了

在VM上供电的脚本


寻找一个简单的脚本以在关闭的Nutanix VM上供电。也许已经有一个线程,但是如果是的话,我无法找到它。



谢谢!!
图标

最好的答案Andymlloyd2019年8月7日,16:21

\n
\n## Get the VM Unique Identifer for the VM you want to power on
\n
\n$myvmname=Read-Host \"Enter the name of the VM to power on\"
\n$myvm= Get-NTNXVM | where {$_.vmname -eq $myvmname}
\n$myvmID = ($myvm.vmid.split(\":\"))[2]
\n
\n## Power on the VM
\n
\nSet-NTNXVMPowerOn -vmid $myvmID
\n
\nEnjoy 🙂","className":"post__content__best_answer"}">
查看原件

该主题已关闭以供评论

4个答复

UserLevel 3
徽章 +2
嗨,我有一个。

我正在上班,然后将其发送给您,这是一个非常好的Python脚本。
UserLevel 3
徽章 +2
嗨,我有一个。

我正在上班,然后将其发送给您,这是一个非常好的Python脚本。




复制并粘贴此代码,用Extension .py保存



安装Python 3解释器和模块(ArgParse,GetPass,请求,Urllib3)



设置值 - 滤波器时,您可以将VM的名称打开 /关闭,也可以关闭以特定前缀开头的所有VM。



例子:







代码:
代码:
#!/usr/bin/env Python3
导入argparse
导入GetPass
导入请求
导入urllib3


urllib3.disable_warnings(urllib3.exceptions.insecurreequestwarning)


版本='1.0.1'
超时= 10


def change_power_state(url,用户名,密码,过滤器,power_state):
base_url = url +“/prismgateway/services/rest/v2.0”
尝试:
r = requests.get(base_url + f'/vms/?filter = vm_name%3D%3D。*{filter}。*',
auth =(用户名,密码),
验证= false,
超时=超时)


如果r.status_code == requests.codes.ok:


实体= r.json()['实体']

如果Len(实体)> 0:
vms = [(e ['name'],e ['uuid'],e ['power_state'])在实体中E ['power_state'])




print(f“ \ nselected vms(总计:{len(vms)}):\ n”)




对于VM中的VM:
print(f“ {vm [0]}(uuid:{vm [1]},power_state:{vm [2]})”)


确认=无
虽然确认不在(“是”,“否”,“ y”,“ n”):
确认=输入(f'\ ndo您要将所有选定VM的功率状态修改为“ {power_state}”(y/n):').Strip()。lower()。下()。


如果在['yes','y']中确认:


print(f'\ nmodifying power状态为VMS到“ {power_state}”:\ n')


对于VM中的VM:
body = {“ transition”:f“ {power_state}”}
r = requests.post(base_url + f'/vms/{vm [1]}/set_power_state/',
json = body,auth =(用户名,密码),
验证= false,
超时=超时)
如果r.status_code == requests.codes.created:
print(f“ {vm [0]}(task_uuid:{r.json()['task_uuid']})”)
别的:
打印(“ http错误:” + str(r.status_code))

别的:
打印(“取消\ noperation。\ n”)
别的:
打印(使用过滤器标准找到f'\ nno vms:“ {filter}”。\ n')




别的:
打印(“ http错误:” + str(r.status_code))
除例外为E:
打印(f“错误:{e}”)


如果__name__ ==“ __ -main __”:
parser = argparse.argumentparser(description ='nutanix vms power状态变化器。与REST API V2兼容。')




parser.add_argument(' - v',' - version',action ='version',version ='%(prog)s v' +版本)
parser.add_argument(' - url',必需= true,
help ='nutanix rest api url。必需的。例如:https://10.10.10.100:9440')
parser.add_argument(' - 用户名',必需= true,
help ='nutanix rest api用户名。必需的。')
parser.add_argument(' - 密码',
help ='nutanix rest API密码。可选,被问到是否省略了。”)
parser.add_argument(' - filter',必需= true,
help ='过滤字符串按名称搜索VM。必需的。')
parser.add_argument(' - power_state',type = str.lower,quilter oilder = true,
选择= ['on','off','powercycle','reset','pause','sustend','remume','acpi_shutdown','acpi_reboot'],
help ='目标功率状态以适用于选定的VM。必需的。')


args = parser.parse_args()


password = args.passs.ifs.passs.passs.passse else getpass.getPass()


change_power_state(args.url,args.username,password,args.filter,args.power_state)
UserLevel 2
徽章 +2
使用PowerShell CMDLET(从Prism/Central下载),然后启动PowerShell:



##获取您要在的VM的VM唯一标识符



$ myvmname = read-host“输入VM的名称登基”

$ myvm = get-ntnxvm |其中{$_。vmname-eq $ myvmname}

$ myvmid =($ myvm.vmid.split(“:”))[2]



## VM上的功率



set -ntnxvmpowon -vmid $ myvmid



享受
UserLevel 2
徽章 +2
@citrixguy1987早上好。我可以请您确认您是否对我的解决方案感到满意,如果可以的话,请标记为最佳答案。



非常感谢



安迪 @andymlloyd
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