1

ESXi ホストがクラッシュした場合など、特定のイベントに対して vsphere を介してスクリプトをトリガーする必要があります。pyvmomi を使用してそれを実行したかったので、vcenter をポーリングせず、アラームでスクリプトをトリガーするようにしました。 http://www.vcritical.com/2009/10/powershell-prevents-datastore-emergency/

私もこれを見まし

しかし、pyvmomi を使用して達成できるかどうか知りたいですか? ありがとう

4

1 に答える 1

0

最初の免責事項: VCSA に追加のソフトウェアを追加することはお勧めしません。特に、マシンの負荷を増加させるものはお勧めしません。私の知る限り、VMWare ではサポートされていません。また、VCSA に安定性の問題が生じる可能性があるため、自己責任で行ってください。心配な場合は、変更を加える前に VMWare アカウント チームに確認してください。

そうは言っても...これは可能です。SLES Linux ボックスで実行される VCSA を使用してこれを実行する必要があるため、Python と pyVmomi の両方が既に存在するため、非常に簡単に実行できます。これは、基盤となる OS が SLES から Photon に変更されたとしても、6.5 がリリースされれば動作します。以下で説明するプロセスは、5.5、6.0、および 6.5 でも同じように機能します。

  1. 作成するアラームがトリガーされたときに実行するスクリプトを作成し、VCSA に配置し/rootます。chmod a+x script.py

  2. 監視しようとしている条件に一致する vCenter でアラームを作成します。既存のアラーム定義が存在する場合がありますが、デフォルトのアラームは変更できないため、独自のアラーム定義を作成する必要があります。

  3. アラーム定義の [アクション] ペインで、[コマンドの実行] を選択します。

  4. 構成ボックスに、実行する実行可能スクリプトへのフル パスを入力します。/root/script.pyアラームを保存します。

アラームがトリガーされると、スクリプトが実行されます。問題がある場合、または動作していないと思われる場合は、VCSA でログ ファイルを見つけて、何が起こっているのかを強調できます。/var/log/vmware/vpxd/vpxd.log

スクリプトの使用を開始する方法を示すために、非常に大雑把な例を作成しました。

#!/usr/bin/python
#   Copyright 2016 Michael Rice <michael@michaelrice.org>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

from __future__ import print_function
import os
import ssl
import sys
import requests

# This is where VMWare keeps the pyVmomi and other libraries
sys.path.extend(os.environ['VMWARE_PYTHON_PATH'].split(';'))

from pyVim import connect
from pyVmomi import vim
requests.packages.urllib3.disable_warnings()
# this is to ignore SSL verification which is helpful for self signed certs
try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context
USER_NAME = "YOUR USER"
PASSWORD = "YOUR PASS"
HOST = "YOUR HOST"
PORT = "443"
service_instance = connect.SmartConnect(host=HOST,
                                        user=USER_NAME,
                                        pwd=PASSWORD,
                                        port=int(PORT))

root_folder = service_instance.content.rootFolder
# again crude example here. use the logging module instead
with open("/var/log/my_script_log_file.txt", 'a') as f:
    print(root_folder.name, file=f)
    for var, val in os.environ.items():
        # When an alarm is triggered and run a lot of environment variables are set. 
        # This will list them all with their values.
        if var.startswith("VMWARE_ALARM"):
            print("{} = {}".format(var, val), file=f)
    print("##########", file=f)
connect.Disconnect(service_instance)
于 2016-11-07T17:18:46.050 に答える