本文整理汇总了Python中avi.sdk.avi_api.ApiSession类的典型用法代码示例。如果您正苦于以下问题:Python ApiSession类的具体用法?Python ApiSession怎么用?Python ApiSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ApiSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reuse_api_session
def test_reuse_api_session(self):
api2 = ApiSession.get_session(api.controller_ip, api.username,
api.password, tenant=api.tenant,
tenant_uuid=api.tenant_uuid,
api_version=api.api_version,
verify=False)
assert api == api2
示例2: main
def main(args):
if args:
# If not specified on the command-line, prompt the user for the
# controller IP address and/or password
controller_ip = args.controller
user = args.user
password = args.password
api = ApiSession.get_session(
controller_ip, user, password, tenant=args.tenant, api_version=args.api_version)
cloud = args.cloud
switchto_cloud(api, cloud)
all_vs = get_all_vs(api)
alb_rule_count = {}
for vs in all_vs:
az = vs.get('azure_availability_set')
if az:
for service in vs['services']:
alb_rule_count[az] = alb_rule_count.get(az, 0) + service['port_range_end'] - service['port'] + 1
print alb_rule_count
示例3: main
def main(args):
api = ApiSession.get_session(args.controller, args.username, args.password,
tenant="*")
if args.vs:
get_config_logs_for_vs(api, args.vs)
else:
get_config_logs_for_all_vses(api)
示例4: convert
def convert(meta, gslb_config_dict, controller_ip, user_name,
password, tenant_name, vs_state, output_dir, version,
report_name, vs_level_status):
vip_cluster_map = None
# If controller ip present then only get configuration from controller.
if controller_ip:
session = ApiSession.get_session(controller_ip, user_name, password)
resp = session.get('configuration/export?full_system=true')
avi_config = json.loads(resp.text)
sites = avi_config['Gslb'][0]['sites']
vip_cluster_map = get_vip_cluster_map(sites)
avi_gslb_config = None
try:
avi_gslb_config = dict()
avi_gslb_config['META'] = meta
gslb_vs_converter = GslbVsConverter()
avi_config = gslb_vs_converter.convert(
gslb_config_dict, avi_gslb_config, vs_state, vip_cluster_map)
ns_util.add_complete_conv_status(
gslb_config_dict, output_dir, avi_config, report_name, vs_level_status)
except:
update_count('error')
LOG.error('Error in config conversion', exc_info=True)
return avi_gslb_config
示例5: create_avi_endpoint
def create_avi_endpoint(tenant):
controller_config = get_avi_controller_config()
print ('Connecting to Avi Controller %s...'%(controller_config['ip']))
print ('User : %s Tenant : %s' %(controller_config['username'],tenant))
return ApiSession.get_session(controller_config['ip'],
controller_config['username'],
controller_config['password'], tenant=tenant)
示例6: setupApiSession
def setupApiSession(self):
self.api = None
api = ApiSession.get_session(self.controller_ip, self.user, self.password,
tenant=self.tenant)
server_cert, server_key, _, _ = get_sample_ssl_params()
ApiUtils(api).import_ssl_certificate('MyCert', server_key, server_cert)
self.api = api
return api
示例7: create_vrf_context
def create_vrf_context(controller_ip, username, password, vrf_name):
session = ApiSession.get_session(controller_ip, username, password)
data = {"name": vrf_name}
json_data = json.dumps(data)
path = "/vrfcontext"
rsp1 = session.post(path, data=json_data)
print rsp1
return rsp1
示例8: create_segroup
def create_segroup(controller_ip, username, password, segroup_name):
session = ApiSession.get_session(controller_ip, username, password)
data = {"name": segroup_name}
json_data = json.dumps(data)
path = "/serviceenginegroup"
rsp1 = session.post(path, data=json_data)
print rsp1
return rsp1
示例9: test_session_reset
def test_session_reset(self):
papi = ApiSession(api.controller_ip, api.username, api.password,
verify=False, api_version=api.api_version)
res = papi.get('pool', params={'fields': 'name'})
assert res.status_code == 200
papi.reset_session()
res = papi.get('pool', params={'fields': 'name'})
assert res.status_code == 200
data = {'name': 'test-reset'}
res = papi.post('pool', data=data)
assert res.status_code == 201
papi.reset_session()
res = papi.delete_by_name('pool', 'test-reset')
assert res.status_code == 204
示例10: test_ssl_vs
def test_ssl_vs(self):
papi = ApiSession(api.controller_ip, api.username, api.password,
verify=False)
ssl_vs_cfg = gSAMPLE_CONFIG["SSL-VS"]
vs_obj = ssl_vs_cfg["vs_obj"]
pool_name = gSAMPLE_CONFIG["SSL-VS"]["pool_obj"]["name"]
resp = papi.post('pool', data=json.dumps(ssl_vs_cfg["pool_obj"]))
pool_ref = papi.get_obj_ref(resp.json())
cert, key, _, _ = get_sample_ssl_params(folder_path='../samples/')
api_utils = ApiUtils(papi)
try:
resp = api_utils.import_ssl_certificate("ssl-vs-kc", key, cert)
ssl_kc = resp.json()
except:
ssl_kc = api.get_object_by_name('sslkeyandcertificate',
'ssl-vs-kc')
ssl_key_and_cert_ref = [papi.get_obj_ref(ssl_kc)]
vs_obj["pool_ref"] = pool_ref
vs_obj["ssl_key_and_certificate_refs"] = ssl_key_and_cert_ref
resp = papi.post('virtualservice', data=json.dumps(vs_obj))
assert resp.status_code < 300
resp = papi.delete_by_name('virtualservice', vs_obj['name'])
assert resp.status_code in (200, 204)
resp = papi.delete_by_name("pool", pool_name)
assert resp.status_code in (200, 204)
resp = api.delete_by_name('sslkeyandcertificate', 'ssl-vs-kc')
assert resp.status_code in (200, 204)
示例11: getAviApiSession
def getAviApiSession():
"""
create session to avi controller
"""
global API
if not API:
API = ApiSession.get_session(
'127.0.0.1', 'admin', 'avi123', tenant='admin')
return API
示例12: getAviApiSession
def getAviApiSession(tenant='admin'):
"""
create session to avi controller
"""
token = os.environ.get('API_TOKEN')
user = os.environ.get('USER')
# tenant=os.environ.get('TENANT')
return ApiSession.get_session("localhost", user, token=token,
tenant=tenant)
示例13: get_vip_cluster_map
def get_vip_cluster_map(sites):
vip_map=dict()
for site in sites:
session = ApiSession.get_session(
site['ip_addresses'][0]['addr'], site['username'], site['password'])
resp = session.get('virtualservice', api_version='17.1.1')
vs_list = json.loads(resp.text)['results']
for vs in vs_list:
vip_map.update(create_map_for_vs(vs, vip_map, site))
return vip_map
示例14: main
def main():
argument_specs = dict(
old_password=dict(type='str', required=True, no_log=True)
)
argument_specs.update(avi_common_argument_spec())
module = AnsibleModule(argument_spec=argument_specs)
if not HAS_AVI:
return module.fail_json(msg=(
'Avi python API SDK (avisdk) is not installed. '
'For more details visit https://github.com/avinetworks/sdk.'))
api_creds = AviCredentials()
api_creds.update_from_ansible_module(module)
password_updated = False
old_password = module.params.get('old_password')
data = {
'old_password': old_password,
'password': api_creds.password
}
password_changed = False
try:
api = ApiSession.get_session(
api_creds.controller, api_creds.username,
password=api_creds.password, timeout=api_creds.timeout,
tenant=api_creds.tenant, tenant_uuid=api_creds.tenant_uuid,
token=api_creds.token, port=api_creds.port)
password_changed = True
return ansible_return(module, None, False, req=data)
except:
pass
if not password_changed:
api = ApiSession.get_session(
api_creds.controller, api_creds.username, password=old_password,
timeout=api_creds.timeout, tenant=api_creds.tenant,
tenant_uuid=api_creds.tenant_uuid, token=api_creds.token,
port=api_creds.port)
rsp = api.put('useraccount', data=data)
if rsp:
return ansible_return(module, rsp, True, req=data)
return module.exit_json(changed=False, obj=data)
示例15: create_tenant
def create_tenant(controller_ip, username, password, name):
""""
Create non default tenant on the given Controller.
"""
session = ApiSession.get_session (controller_ip, username, password)
data = {'local': True, 'name': name}
json_data = json.dumps (data)
path = "/tenant?"
rsp = session.post (path, data=json_data)
print rsp
return