def start_tag(tag): try: api = API(url=URL, username=USERNAME, password=PASSWORD, ca_file=CERT, insecure=True) print "Connected to %s successfully!" % api.get_product_info().name for vm in api.vms.list(query="tag=%s" % tag): print("VM %s is in state %s" % (vm.get_name(), vm.status.state)) # print vm.get_name() # print(dir(vm)) try: if vm.status.state != 'up': # print("VM %s is in state %s" %( vm.get_name() , vm.status.state)) print 'Starting VM' # vm.get(VM_NAME).start() vm.start() print 'Waiting for VM to reach Up status' # while vm.get(VM_NAME).status.state != 'up': count = 30 while vm.status.state != 'up' and count > 0: time.sleep(1) count = count - 1 else: print 'VM already up' except Exception as e: print 'Failed to Start VM:\n%s' % str(e) time.sleep(6) api.disconnect() except Exception as ex: print "Unexpected error: %s" % ex
def _initialize_api(hostname, username, password, ca, insecure): """ Initialize the oVirt RESTful API """ url = 'https://{hostname}/ovirt-engine/api'.format( hostname=hostname, ) api = API(url=url, username=username, password=password, ca_file=ca, validate_cert_chain=not insecure) pi = api.get_product_info() if pi is not None: vrm = '%s.%s.%s' % ( pi.get_version().get_major(), pi.get_version().get_minor(), pi.get_version().get_revision() ) logging.debug("API Vendor(%s)\tAPI Version(%s)" % ( pi.get_vendor(), vrm) ) else: api.test(throw_exception=True) return api
def get_connection(location): api = API( url="https://" + locations.get(location, "host"), username=locations.get(location, "username"), password=locations.get(location, "password"), ca_file=locations.get(location, "certificate") ) print "Connected to %s successfully!" % api.get_product_info().name return api
from ovirtsdk.api import API from ovirtsdk.xml import params VERSION = params.Version(major='3', minor='5') URL = 'https://rhevm.example.com/ovirt-engine/api' CA = '/etc/pki/ovirt-engine/ca.pem' USERNAME = '******' PASSWORD = '******' HOST_NAME = 'rhevh1' PM_ADDRESS = '192.168.101.11' try: api = API(url=URL, username=USERNAME, password=PASSWORD, ca_file=CA) print "Connected to %s successfully!" % api.get_product_info().name except Exception as err: print "Connection failed: %s" % err try: host = api.hosts.get(HOST_NAME) pm = host.get_power_management() pm.set_type('ilo') pm.set_enabled(True) pm.set_address(PM_ADDRESS) pm.set_username('root') pm.set_password('Secret') host.update() except Exception as err:
USERNAME = '******' PASSWORD = '******' DC_NAME = 'Default' CLUSTER_NAME = 'Default' HOST_NAME = 'rhevh1' # HOST_NAME = 'rhevh1' HOST_ADDRESS = '192.168.100.11' ROOT_PASSWORD = '******' # PM_ADDRESS = '192.168.101.11' try: api = API(url=URL, username=USERNAME, password=PASSWORD, ca_file=CA) print "Connected to %s successfully!" % api.get_product_info().name except Exception as err: print "Connection failed: %s" % err try: pm = params.PowerManagement() pm.set_type('xvm') # Note: Fencing type xvm is for nested HV # Note: And this needs to be added to RHEV first pm.set_enabled(True) pm.set_address(PM_ADDRESS) pm.set_username('root') pm.set_password('Secret') pm.set_options(params.Options(option=[ params.Option(name='domain', value='rhev-h-3')]))