本文整理汇总了Python中vnc_api.vnc_api.VncApi.fabric_create方法的典型用法代码示例。如果您正苦于以下问题:Python VncApi.fabric_create方法的具体用法?Python VncApi.fabric_create怎么用?Python VncApi.fabric_create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vnc_api.vnc_api.VncApi
的用法示例。
在下文中一共展示了VncApi.fabric_create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SanityBase
# 需要导入模块: from vnc_api.vnc_api import VncApi [as 别名]
# 或者: from vnc_api.vnc_api.VncApi import fabric_create [as 别名]
class SanityBase(object):
"""Base class for fabric ansible sanity tests"""
@staticmethod
def _init_logging(cfg, name):
logger = logging.getLogger('sanity_test')
logger.setLevel(cfg['level'])
file_handler = logging.FileHandler(
'%s/fabric_ansibile_%s.log' % (cfg['file']['dir'], name), mode='w')
file_handler.setLevel(cfg['file']['level'])
console_handler = logging.StreamHandler()
console_handler.setLevel(cfg['console'])
formatter = logging.Formatter(
'%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y/%m/%d %H:%M:%S')
file_handler.setFormatter(formatter)
console_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.addHandler(console_handler)
return logger
# end _init_logging
def test(self):
"""Override this method in the derived class"""
pass
def __init__(self, cfg, name):
if cfg is None:
raise KeyError("Missing required args: cfg")
if name is None:
raise KeyError("Missing required args: name")
self._name = name
self._timeout = cfg['wait_for_job']['timeout']
self._max_retries = cfg['wait_for_job']['max_retries']
self._logger = SanityBase._init_logging(cfg['log'], name)
self._api_server = cfg['api_server']
self._analytics = cfg['analytics']
self._api = VncApi(
api_server_host=self._api_server['host'],
api_server_port=self._api_server['port'],
username=self._api_server['username'],
password=self._api_server['password'],
tenant_name=self._api_server['tenant'])
# end __init__
def create_fabric(self, fab_name, prouter_passwords):
"""create fabric with list of device passwords"""
self._logger.info('Creating fabric: %s', fab_name)
fq_name = ['default-global-system-config', fab_name]
fab = Fabric(
name=fab_name,
fq_name=fq_name,
parent_type='global-system-config',
fabric_credentials={
'device_credential': [{
'credential': {
'username': 'root', 'password': passwd
},
'vendor': 'Juniper',
'device_family': None
} for passwd in prouter_passwords]
}
)
try:
fab_uuid = self._api.fabric_create(fab)
fab = self._api.fabric_read(id=fab_uuid)
except RefsExistError:
self._logger.warn("Fabric '%s' already exists", fab_name)
fab = self._api.fabric_read(fq_name=fq_name)
self._logger.debug(
"Fabric created:\n%s",
pprint.pformat(self._api.obj_to_dict(fab), indent=4))
return fab
# end _create_fabric
def add_mgmt_ip_namespace(self, fab, name, cidrs):
"""add management ip prefixes as fabric namespace"""
ns_name = 'mgmt_ip-' + name
self._logger.info(
'Adding management ip namespace "%s" to fabric "%s" ...',
ns_name, fab.name)
subnets = []
for cidr in cidrs:
ip_prefix = cidr.split('/')
subnets.append({
'ip_prefix': ip_prefix[0],
'ip_prefix_len': ip_prefix[1]
})
ns_fq_name = fab.fq_name + [ns_name]
namespace = FabricNamespace(
name=ns_name,
fq_name=ns_fq_name,
parent_type='fabric',
fabric_namespace_type='IPV4-CIDR',
#.........这里部分代码省略.........