本文整理汇总了Python中networkapi.plugins.factory.PluginFactory类的典型用法代码示例。如果您正苦于以下问题:Python PluginFactory类的具体用法?Python PluginFactory怎么用?Python PluginFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PluginFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _remove_svi
def _remove_svi(equipment, vlan_num):
equip_plugin = PluginFactory.factory(equipment)
equip_plugin.connect()
output = equip_plugin.remove_svi(vlan_num)
equip_plugin.close()
return output
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:7,代码来源:v1.py
示例2: _applyconfig
def _applyconfig(equipment, filename, equipment_access=None, source_server=None, port=22):
"""Apply configuration file on equipment
Args:
equipment: networkapi.equipamento.Equipamento()
filename: relative file path from TFTPBOOT_FILES_PATH to apply in equipment
equipment_access: networkapi.equipamento.EquipamentoAcesso() to use
source_server: source TFTP server address
port: ssh tcp port
Returns:
equipment output
Raises:
"""
if equipment.maintenance is True:
return 'Equipment is in maintenance mode. No action taken.'
if source_server is None:
source_server = TFTP_SERVER_ADDR
# TODO: Handle exceptions from the following methods and generate response
# for the caller
equip_plugin = PluginFactory.factory(equipment)
equip_plugin.connect()
equip_plugin.ensure_privilege_level()
equip_output = equip_plugin.copyScriptFileToConfig(filename)
equip_plugin.close()
return equip_output
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:32,代码来源:facade.py
示例3: undeploy_neighbor_v6
def undeploy_neighbor_v6(neighbor_id):
neighbor = NeighborV6.objects.get(id=neighbor_id)
if not neighbor.created:
raise exceptions.NeighborV6IsUndeployed(neighbor)
locks_list = lock_resources_used_by_neighbor_v6(neighbor)
try:
get_created_neighbors_v4_shares_same_eqpt_and_peer(neighbor)
get_created_neighbors_v6_shares_same_eqpt_and_peer(neighbor)
eqpt = get_v6_equipment(neighbor)
plugin = PluginFactory.factory(eqpt)
plugin.bgp().undeploy_neighbor(neighbor)
neighbor.deploy()
except Exception as e:
raise api_rest_exceptions.NetworkAPIException(str(e))
finally:
destroy_lock(locks_list)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:25,代码来源:facade.py
示例4: deploy_neighbor_v4
def deploy_neighbor_v4(neighbor_id):
neighbor = NeighborV4.objects.get(id=neighbor_id)
if neighbor.created:
raise NeighborV4IsDeployed(neighbor)
locks_list = lock_resources_used_by_neighbor_v4(neighbor)
try:
depl_v4 = get_created_neighbors_v4_shares_same_eqpt_and_peer(neighbor)
depl_v6 = get_created_neighbors_v6_shares_same_eqpt_and_peer(neighbor)
eqpt = get_v4_equipment(neighbor)
plugin = PluginFactory.factory(eqpt)
plugin.bgp().deploy_neighbor(neighbor)
neighbor.deploy()
except Exception as e:
raise NetworkAPIException(str(e))
finally:
destroy_lock(locks_list)
开发者ID:pantuza,项目名称:GloboNetworkAPI,代码行数:25,代码来源:facade.py
示例5: __applyConfig
def __applyConfig(equipment,filename, equipment_access=None,source_server=None,port=22):
'''Apply configuration file on equipment
Args:
equipment: networkapi.equipamento.Equipamento()
filename: relative file path from TFTPBOOT_FILES_PATH to apply in equipment
equipment_access: networkapi.equipamento.EquipamentoAcesso() to use
source_server: source TFTP server address
port: ssh tcp port
Returns:
equipment output
Raises:
'''
if equipment.maintenance == True:
return "Equipment is in maintenance mode. No action taken."
if source_server == None:
source_server = TFTP_SERVER_ADDR
equip_plugin = PluginFactory.factory(equipment)
equip_plugin.connect()
equip_plugin.ensure_privilege_level()
equip_output = equip_plugin.copyScriptFileToConfig(filename)
equip_plugin.close()
return equip_output
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:29,代码来源:facade.py
示例6: test_factory_bgp_undeploy_neighbor
def test_factory_bgp_undeploy_neighbor(self):
equipment = self._mock_equipment()
plugin = PluginFactory.factory(equipment)
neighbor = {}
self.assertEqual(hasattr(plugin.bgp(neighbor), 'undeploy_neighbor'),
True)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:8,代码来源:test_cli.py
示例7: test_factory_bgp_deploy_prefix_list
def test_factory_bgp_deploy_prefix_list(self):
equipment = self._mock_equipment()
plugin = PluginFactory.factory(equipment)
neighbor = {}
self.assertEqual(
hasattr(plugin.bgp(neighbor), 'deploy_prefix_list'), True)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:8,代码来源:test_cli.py
示例8: remove_svi
def remove_svi(equipment, vlan_num):
"""Call function "remove_svi" of Plugin for model of equipment."""
equip_plugin = PluginFactory.factory(equipment)
equip_plugin.connect()
output = equip_plugin.remove_svi(vlan_num)
equip_plugin.close()
return output
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:9,代码来源:utils.py
示例9: flush_flows
def flush_flows(env_id):
""" Flushes flow from a environment without restore it """
eqpts = get_controller_by_envid(env_id)
for eqpt in eqpts:
plugin = PluginFactory.factory(eqpt, env_id=env_id)
try:
plugin.flush_flows()
except Exception as e:
log.error(e)
raise NetworkAPIException('Failed to flush Controller '
'plugin. %s' % e)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:11,代码来源:facade.py
示例10: _prepare_apply_state
def _prepare_apply_state(pools, user=None):
load_balance = dict()
keys = list()
for pool in pools:
server_pool = ServerPool.objects.get(id=pool['id'])
server_pool_members = server_pool.serverpoolmember_set.all()
if pool['server_pool_members']:
equips = _validate_pool_members_to_apply(pool, user)
keys.append(sorted([str(eqpt.id) for eqpt in equips]))
for e in equips:
eqpt_id = str(e.id)
equipment_access = EquipamentoAcesso.search(
equipamento=e.id
)
plugin = PluginFactory.factory(e)
if not load_balance.get(eqpt_id):
load_balance[eqpt_id] = {
'plugin': plugin,
'access': equipment_access,
'pools': [],
}
mbs = pool['server_pool_members']
idx_mbs = [mb['id'] for mb in mbs]
load_balance[eqpt_id]['pools'].append({
'id': server_pool.id,
'nome': server_pool.identifier,
'pools_members': [{
'id': pool_member.id,
'ip': pool_member.ip.ip_formated
if pool_member.ip else pool_member.ipv6.ip_formated,
'port': pool_member.port_real,
'member_status': mbs
[idx_mbs.index(pool_member.id)]['member_status']
} for pool_member in server_pool_members
if pool_member.id in idx_mbs]
})
# pools are in differents load balancers
keys = [','.join(key) for key in keys]
if len(list(set(keys))) > 1:
raise Exception('Pools are in differents load balancers')
return load_balance
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:52,代码来源:deploy.py
示例11: setUp
def setUp(self):
# Must chose the equipment with the right version running on docker
# Beryllium
self.equipment = Equipamento.objects.filter(id=10).uniqueResult()
# Nitrogen
#self.equipment = Equipamento.objects.filter(id=11).uniqueResult()
self.equipment_access = EquipamentoAcesso.objects.filter(id=1).uniqueResult()
self.utils.set_controller_endpoint(self.equipment_access)
self.odl = PluginFactory.factory(self.equipment)
self.flow_key = "flow-node-inventory:flow"
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:13,代码来源:test_generic_odl_plugin.py
示例12: insert_flow
def insert_flow(env_id, data, user_id):
eqpts = get_controller_by_envid(env_id)
plugins = []
for eqpt in eqpts:
plugins.append(PluginFactory.factory(eqpt, env_id=env_id))
try:
return async_add_flow.apply_async(
args=[plugins, user_id, data], queue='napi.odl_flow'
)
except Exception as e:
log.error(e)
raise NetworkAPIException('Failed to insert flow(s) '
'plugin. %s' % e)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:13,代码来源:facade.py
示例13: update_flows
def update_flows(env_id, data, user_id):
""" Call equipment plugin to asynchronously flush the environment """
eqpts = get_controller_by_envid(env_id)
plugins = []
for eqpt in eqpts:
plugins.append(PluginFactory.factory(eqpt, env_id=env_id))
try:
return async_flush_environment.apply_async(
args=[plugins, user_id, data], queue='napi.odl_flow'
)
except Exception as e:
log.error(e)
raise NetworkAPIException('Failed to flush flow(s) '
'from environment: %s \n%s' % (env_id, e))
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:15,代码来源:facade.py
示例14: delete_flow
def delete_flow(env_id, flow_id, user_id):
""" Deletes one flow by id using the async task """
eqpts = get_controller_by_envid(env_id)
plugins = []
for eqpt in eqpts:
plugins.append(PluginFactory.factory(eqpt, env_id=env_id))
try:
return async_delete_flow.apply_async(
args=[plugins, user_id, flow_id], queue='napi.odl_flow'
)
except Exception as err:
log.error(err)
raise NetworkAPIException('Failed to delete flow with error: %s' % err)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:16,代码来源:facade.py
示例15: create_v3
def create_v3(self, vip_port_map):
# save port
facade_eqpt = get_app('api_equipment', 'facade')
self.vip_request = VipRequest.get_by_pk(
vip_port_map.get('vip_request'))
self.port = vip_port_map.get('port')
eqpts = facade_eqpt.get_eqpt_by_envvip(
self.vip_request.environmentvip.id)
if eqpts:
plugin = PluginFactory.factory(eqpts[0])
identifier = plugin.get_name_eqpt(
self.vip_request, vip_port_map['port'])
self.identifier = identifier
self.save()
# L4 Protocol
opt = VipRequestPortOptionVip()
opt_map = {
'vip_request_port': self.id,
'optionvip': vip_port_map['options']['l4_protocol']
}
opt.create_v3(opt_map)
# L7 Protocol
opt = VipRequestPortOptionVip()
opt_map = {
'vip_request_port': self.id,
'optionvip': vip_port_map['options']['l7_protocol']
}
opt.create_v3(opt_map)
# Pools
for pool in vip_port_map.get('pools'):
pool_map = {
'vip_request_port': self.id,
'server_pool': pool.get('server_pool'),
'optionvip': pool.get('l7_rule'),
'val_optionvip': pool.get('l7_value'),
'order': pool.get('order')
}
pl = VipRequestPortPool()
pl.create_v3(pool_map)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:46,代码来源:models.py
示例16: list_flows_by_envid
def list_flows_by_envid(env_id, flow_id=0):
eqpts = get_controller_by_envid(env_id)
flows_list = {}
for eqpt in eqpts:
plugin = PluginFactory.factory(eqpt, env_id=env_id)
try:
if flow_id > 0:
flows_list.update(plugin.get_flow(flow_id=flow_id))
else:
flows_list.update(plugin.get_flows())
except Exception as e:
log.error(e)
raise NetworkAPIException('Failed to list flow(s)'
'plugin. %s' % e)
return flows_list
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:18,代码来源:facade.py
示例17: get_poolmember_state
def get_poolmember_state(servers_pools):
"""
Return Pool Members State
"""
load_balance = {}
for server_pool in servers_pools:
pools_members = []
server_pool_members = ServerPoolMember.objects.filter(
server_pool=server_pool)
for pool_member in server_pool_members:
if pool_member.ipv6 is None:
ip = pool_member.ip.ip_formated
else:
ip = pool_member.ipv6.ip_formated
pools_members.append({
'id': pool_member.id,
'ip': ip,
'port': pool_member.port_real,
'member_status': pool_member.member_status
})
if pools_members:
# pool_name = server_pool.identifier
pool_id = server_pool.id
equips = EquipamentoAmbiente.objects.filter(
ambiente__id=server_pool.environment.id,
equipamento__tipo_equipamento__tipo_equipamento=u'Balanceador')
equipment_list = [e.equipamento for e in equips]
if all_equipments_are_in_maintenance(equipment_list):
raise AllEquipmentsAreInMaintenanceException()
for e in equips:
eqpt_id = str(e.equipamento.id)
equipment_access = EquipamentoAcesso.search(
equipamento=e.equipamento.id,
protocolo="https"
).uniqueResult()
equipment = Equipamento.get_by_pk(e.equipamento.id)
plugin = PluginFactory.factory(equipment)
if not load_balance.get(eqpt_id):
load_balance[eqpt_id] = {
'plugin': plugin,
'fqdn': equipment_access.fqdn,
'user': equipment_access.user,
'password': equipment_access.password,
'pools': [],
}
load_balance[eqpt_id]['pools'].append({
'id': server_pool.id,
'nome': server_pool.identifier,
'pools_members': pools_members
})
for lb in load_balance:
ps = {}
status = {}
# call plugin to get state member
states = load_balance[lb]['plugin'].getStateMember(load_balance[lb])
for idx, state in enumerate(states):
pool_id = load_balance[lb]['pools'][idx]['id']
if not ps.get(pool_id):
ps[pool_id] = {}
status[pool_id] = {}
# populate variable for to verify diff states
for idx_m, st in enumerate(state):
member_id = load_balance[lb]['pools'][idx]['pools_members'][idx_m]['id']
if not ps[pool_id].get(member_id):
ps[pool_id][member_id] = []
ps[pool_id][member_id].append(st)
status[pool_id][member_id] = st
# Verify diff state of pool member in eqpts
for idx in ps:
for idx_m in ps[idx]:
if len(set(ps[idx][idx_m])) > 1:
msg = 'There are states differents in equipments.'
log.error(msg)
raise exceptions.DiffStatesEquipament(msg)
return status
开发者ID:jotagesales,项目名称:GloboNetworkAPI,代码行数:94,代码来源:facade.py
示例18: set_poolmember_state
def set_poolmember_state(pools):
"""
Set Pool Members state
"""
try:
load_balance = {}
for pool in pools:
pools_members = []
q_filters = []
for pool_member in pool['server_pool_members']:
port_real = pool_member['port_real']
if pool_member['ipv6'] is None:
ip = pool_member['ip']['ip_formated']
ip_ft = '.'.join(str(x) for x in [
pool_member['ip']['oct1'],
pool_member['ip']['oct2'],
pool_member['ip']['oct3'],
pool_member['ip']['oct4']])
if ip != ip_ft:
raise exceptions.InvalidIpNotExist()
q_filters.append({
'ip__oct1': pool_member['ip']['oct1'],
'ip__oct2': pool_member['ip']['oct2'],
'ip__oct3': pool_member['ip']['oct3'],
'ip__oct4': pool_member['ip']['oct4'],
'port_real': port_real
})
else:
ip = pool_member['ipv6']['ip_formated']
ip_ft = '.'.join(str(x) for x in [
pool_member['ipv6']['block1'],
pool_member['ipv6']['block2'],
pool_member['ipv6']['block3'],
pool_member['ipv6']['block4'],
pool_member['ipv6']['block5'],
pool_member['ipv6']['block6'],
pool_member['ipv6']['block7'],
pool_member['ipv6']['block8']])
if ip != ip_ft:
raise exceptions.InvalidIpNotExist()
q_filters.append({
'ipv6__block1': pool_member['ipv6']['block1'],
'ipv6__block2': pool_member['ipv6']['block2'],
'ipv6__block3': pool_member['ipv6']['block3'],
'ipv6__block4': pool_member['ipv6']['block4'],
'ipv6__block5': pool_member['ipv6']['block5'],
'ipv6__block6': pool_member['ipv6']['block6'],
'ipv6__block7': pool_member['ipv6']['block7'],
'ipv6__block8': pool_member['ipv6']['block8'],
'port_real': port_real
})
pools_members.append({
'id': pool_member['id'],
'ip': ip,
'port': port_real,
'member_status': pool_member['member_status']
})
server_pool_members = ServerPoolMember.objects.filter(
reduce(lambda x, y: x | y, [Q(**q_filter) for q_filter in q_filters]), server_pool=pool['server_pool']['id'])
if len(server_pool_members) != len(pools_members):
raise exceptions.PoolmemberNotExist()
pool_name = pool['server_pool']['identifier']
server_pools = ServerPool.objects.filter(identifier=pool_name)
if not server_pools:
raise exceptions.PoolNotExist()
equips = EquipamentoAmbiente.objects.filter(
ambiente__id=pool['server_pool']['environment']['id'],
equipamento__tipo_equipamento__tipo_equipamento=u'Balanceador')
equipment_list = [e.equipamento for e in equips]
if all_equipments_are_in_maintenance(equipment_list):
raise AllEquipmentsAreInMaintenanceException()
for e in equips:
eqpt_id = str(e.equipamento.id)
equipment_access = EquipamentoAcesso.search(
equipamento=e.equipamento.id,
protocolo="https"
).uniqueResult()
equipment = Equipamento.get_by_pk(e.equipamento.id)
plugin = PluginFactory.factory(equipment)
#.........这里部分代码省略.........
开发者ID:jotagesales,项目名称:GloboNetworkAPI,代码行数:101,代码来源:facade.py
示例19: prepare_apply
#.........这里部分代码省略.........
if validation.get('type') == 'portoptionvip':
validated &= valid_expression(
validation.get('operator'),
int(port['options'][
validation.get('variable')]),
int(validation.get('value'))
)
if validation.get('type') == 'field' and validation.get('variable') == 'cluster_unit':
validated &= valid_expression(
validation.get('operator'),
cluster_unit,
validation.get('value')
)
if validated:
use = condicional.get('use')
for item in use:
definitions = item.get('definitions')
eqpts = item.get('eqpts')
if eqpts:
eqpts = Equipamento.objects.filter(
id__in=eqpts,
maintenance=0,
tipo_equipamento__tipo_equipamento=u'Balanceador').distinct()
if facade_eqpt.all_equipments_are_in_maintenance(equips):
raise exceptions_eqpt.AllEquipmentsAreInMaintenanceException()
if user:
if not facade_eqpt.all_equipments_can_update_config(equips, user):
raise exceptions_eqpt.UserDoesNotHavePermInAllEqptException(
'User does not have permission to update conf in eqpt. \
Verify the permissions of user group with equipment group. Vip:{}'.format(
vip_request['id']))
for eqpt in eqpts:
eqpt_id = str(eqpt.id)
if not load_balance.get(eqpt_id):
equipment_access = EquipamentoAcesso.search(
equipamento=eqpt.id
)
plugin = PluginFactory.factory(
eqpt)
load_balance[eqpt_id] = {
'plugin': plugin,
'access': equipment_access,
'vips': [],
'layers': {},
}
idx_layer = str(idx)
idx_port_str = str(port['port'])
if not load_balance[eqpt_id]['layers'].get(id_vip):
load_balance[eqpt_id][
'layers'][id_vip] = dict()
if load_balance[eqpt_id]['layers'][id_vip].get(idx_layer):
if load_balance[eqpt_id]['layers'][id_vip].get(idx_layer).get('definitions').get(idx_port_str):
load_balance[eqpt_id]['layers'][id_vip][idx_layer][
'definitions'][idx_port_str] += definitions
else:
load_balance[eqpt_id]['layers'][id_vip][idx_layer][
'definitions'][idx_port_str] = definitions
else:
load_balance[eqpt_id]['layers'][id_vip][idx_layer] = {
'vip_request': vip_request,
'definitions': {
idx_port_str: definitions
}
}
# In first validated==True stops conditionals.
# Removing this break will add a wrong
# conditional.
break
for e in equips:
eqpt_id = str(e.id)
if not load_balance.get(eqpt_id):
equipment_access = EquipamentoAcesso.search(
equipamento=e.id
)
plugin = PluginFactory.factory(e)
load_balance[eqpt_id] = {
'plugin': plugin,
'access': equipment_access,
'vips': [],
'layers': {},
}
load_balance[eqpt_id]['vips'].append({'vip_request': vip_request})
return load_balance
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:101,代码来源:v3.py
示例20: update_v3
def update_v3(self, vip_port_map):
facade_eqpt = get_app('api_equipment', 'facade')
if not self.identifier or self.port != vip_port_map['port']:
eqpts = facade_eqpt\
.get_eqpt_by_envvip(self.vip_request.environmentvip.id)
if eqpts:
plugin = PluginFactory.factory(eqpts[0])
identifier = plugin.get_name_eqpt(
self.vip_request,
vip_port_map['port']
)
self.identifier = identifier
self.save()
# L4 Protocol
try:
opt = VipRequestPortOptionVip.objects.get(
vip_request_port_id=self.id,
optionvip_id=vip_port_map.get('options').get('l4_protocol'))
except:
opt = VipRequestPortOptionVip()
opt_map = {
'vip_request_port': self.id,
'optionvip': vip_port_map['options']['l4_protocol']
}
opt.create_v3(opt_map)
# L7 Protocol
try:
opt = VipRequestPortOptionVip.objects.get(
vip_request_port_id=self.id,
optionvip_id=vip_port_map.get('options').get('l7_protocol'))
except:
opt = VipRequestPortOptionVip()
opt_map = {
'vip_request_port': self.id,
'optionvip': vip_port_map['options']['l7_protocol']
}
opt.create_v3(opt_map)
# Deletes option by port
VipRequestPortOptionVip.objects.filter(
vip_request_port_id=self.id
).exclude(
optionvip_id__in=[
vip_port_map.get('options').get('l4_protocol'),
vip_port_map.get('options').get('l7_protocol')]
).delete()
# Pools
pools = list()
for pool in vip_port_map.get('pools'):
pool_map = {
'vip_request_port': self.id,
'server_pool': pool.get('server_pool'),
'optionvip': pool.get('l7_rule'),
'val_optionvip': pool.get('l7_value'),
'order': pool.get('order')
}
try:
pl = VipRequestPortPool.objects.get(
vip_request_port=self.id,
id=pool.get('id'))
except:
pl = VipRequestPortPool()
pl.create_v3(pool_map)
else:
pl.update_v3(pool_map)
pools.append(pl.id)
# Deletes pool by port
VipRequestPortPool.objects.filter(
vip_request_port=self.id
).exclude(
id__in=pools
).delete()
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:78,代码来源:models.py
注:本文中的networkapi.plugins.factory.PluginFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论