Пример #1
0
def get_service_url(opts, config):
    """ Return the service url for the vSphere SDK """

    protocol  = path = ''
    server = conf.get_value(opts, config, 'server')
    if not server.startswith('http'):
        protocol = 'https://'
    if server.split('/')[-1] != 'sdk':
        path = '/sdk'
    return ''.join([protocol, server, path])
Пример #2
0
def main(opts):
    config_mode = (opts.action in ACTIONS[:2]) and 'r' or 'w'
    config = conf.load_config(opts.config, config_mode)
    serviceURL = api.get_service_url(opts, config)
    username = conf.get_value(opts, config, 'username')
    password = conf.get_value(opts, config, 'password', secret=True)

    try:
        vim_client = api.connect(serviceURL, username, password)
   
        if opts.action == 'verify':
            verify.do_verify(config, opts, vim_client)
        elif opts.action == 'pillage':
            pillage.do_pillage(config, opts, vim_client)
        elif opts.action == 'repair':
            repair.do_repair(config, opts, vim_client)
        vim_client.Disconnect()
        rc = 0
    except SystemError, e:
        print(str(e.args))
        rc = 1
Пример #3
0
def do_verify(config, opts, client):
    """ Verify running config against config file. """
    vhost = conf.get_value(opts, config, 'vhost', prompt=False)
    hosts = api.get_hosts(client, vhost)

    print('')
    vswitches = config['vswitch']
    portgroups = config['portgroup']
    for host in hosts:
        print("Verifying config on %s ... " % host.Name)
        verify_vswitches(host.Config, config)
        verify_portgroups(host.Config, config)
        continue
Пример #4
0
def execute_sql(sql):
    dirpath = os.path.dirname(os.path.abspath(__file__))
    conf.init(dirpath + "/db.ini")

    section = 'mysql'
    host = conf.get_value(section, "host")
    username = conf.get_value(section, "username")
    password = conf.get_value(section, "password")
    database = conf.get_value(section, "database")
    db = MySQLdb.connect(host, username, password, database)
    cursor = db.cursor()

    # sql = db.escape_string(sql)

    logger.debug("execute sql:" + sql)

    try:
        cursor.execute(sql)
        db.commit()
    except Exception, err:
        print(err)
        db.rollback()
Пример #5
0
def execute_sql(sql):
	dirpath = os.path.dirname(os.path.abspath(__file__))
	conf.init(dirpath + "/db.ini")

	section = 'mysql'
	host = conf.get_value(section, "host")
	username = conf.get_value(section, "username")
	password = conf.get_value(section, "password")
	database = conf.get_value(section, "database")
	db = MySQLdb.connect(host,username,password,database)
	cursor = db.cursor()
	
	# sql = db.escape_string(sql)
	
	logger.debug("execute sql:" + sql)

	try:
		cursor.execute(sql)
		db.commit()
	except Exception,err:
		print(err)
		db.rollback()
Пример #6
0
def do_pillage(config, opts, client):
    """ Pull the config from the specified VMware host and save it in the
    config.

    If no VMware host server was specified, it will pull the config from the
    first host returned from FindEntityView.

    """
    vhost = conf.get_value(opts, config, "vhost", prompt=False)
    host = api.get_host(client, vhost)

    pillage_vswitch_config(host.Config, config)
    pillage_portgroup_config(host.Config, config)

    config.write()