Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
This method returns the Rn for a managed object.
"""
import re
rn_pattern = self.mo_meta.rn
for prop in re.findall(r"""\[([^\]]*)\]""", rn_pattern):
if prop in self.prop_meta:
if getattr(self, prop):
rn_pattern = re.sub(r"""\[%s\]""" % prop,
'%s' % getattr(self, prop), rn_pattern)
else:
log.debug('Property "%s" was None in make_rn' % prop)
if self.rn_is_special_case():
return self.rn_get_special_case()
raise UcscValidationException(
'Property "%s" was None in make_rn' % prop)
else:
log.debug(
'Property "%s" was not found in make_rn arguments' % prop)
if self.rn_is_special_case():
return self.rn_get_special_case()
raise UcscValidationException(
'Property "%s" was not found in make_rn arguments' % prop)
return rn_pattern
username (str): Username for the remote server access
password (str): Password for the remote server access
Example:
firmware_add_remote(handle,
file_name="ucs-k9-bundle-b-series.3.1.1h.B.bin",
remote_path="/remote_path/", hostname="10.10.1.1",
protocol="scp",username="guest",password="password")
'''
if not hostname:
raise UcscValidationException("Missing hostname argument")
if not remote_path:
raise UcscValidationException("Missing remote_path argument")
if not file_name:
raise UcscValidationException("Missing file_name argument")
if not protocol:
raise UcscValidationException("Missing protocol argument")
if protocol is not FirmwareDownloaderConsts.PROTOCOL_TFTP:
if not username:
raise UcscValidationException("Missing username argument")
if not password:
raise UcscValidationException("Missing password argument")
top_system = TopSystem()
firmware_catalogue = FirmwareCatalogue(parent_mo_or_dn=top_system)
firmware_downloader = FirmwareDownloader(
parent_mo_or_dn=firmware_catalogue,
file_name=file_name)
firmware_downloader.remote_path = remote_path
firmware_downloader.protocol = protocol
firmware_downloader.server = hostname
firmware_downloader.user = username
_backup(handle, file_dir=file_dir, file_name=file_name)\n
_backup(handle, file_dir=file_dir, file_name=file_name,
remote_enabled=True, protocol='scp',hostname='192.168.1.1',
username='admin',password='password')\n
"""
from ..mometa.mgmt.MgmtBackup import MgmtBackup, MgmtBackupConsts
from ..mometa.top.TopSystem import TopSystem
backup_type = "full-state"
if not file_dir:
raise UcscValidationException("Missing file_dir argument")
if not file_name:
raise UcscValidationException("Missing file_name argument")
top_system = TopSystem()
if remote_enabled:
_validate_remote_host_args(protocol, hostname, username, password)
if (not file_name.endswith('.tgz')):
raise UcscValidationException(
"file_name must be .tgz format")
file_path = os.path.join(file_dir, file_name)
mgmt_backup = MgmtBackup(
parent_mo_or_dn=top_system,
hostname=hostname,
admin_state=MgmtBackupConsts.ADMIN_STATE_ENABLED,
proto=protocol,
type=backup_type,
def _schedule_export_config(handle, descr, sched_name,
max_bkup_files, remote_enabled,
protocol, hostname, file_path,
username, password,
parent_mo_or_dn):
"""
Internal method to schedule and take remote backup of UcsCentral and Domain
config-all backup
"""
from ..mometa.mgmt.MgmtCfgExportPolicy import MgmtCfgExportPolicy, \
MgmtCfgExportPolicyConsts
if remote_enabled:
if not file_path:
raise UcscValidationException("Missing file_path argument")
_validate_remote_host_args(protocol, hostname, username, password)
proto = protocol
host = hostname
remote_file = file_path
user = username
pwd = password
else:
proto = MgmtCfgExportPolicyConsts.PROTO_NFS_COPY
host = ""
remote_file = " "
user = ""
pwd = ""
cfg_export_pol = MgmtCfgExportPolicy(
parent_mo_or_dn=parent_mo_or_dn,
import from remote:
_import_config(handle, file_name=file_name,
file_location="remote",
file_dir=file_dir
protocol='scp',hostname='192.168.1.1',
username='admin',password='password')\n
"""
from ..mometa.top.TopSystem import TopSystem
from ..mometa.mgmt.MgmtDataImporter import MgmtDataImporter, \
MgmtDataImporterConsts
if not file_name:
raise UcscValidationException("Missing file_name argument")
if file_location != "ucscentral":
if not file_dir:
raise UcscValidationException("Missing file_dir argument")
if (not file_name.endswith('.tgz')):
raise UcscValidationException("file_name must be .tgz format")
top_system = TopSystem()
if file_location == "remote":
file_path = os.path.join(file_dir, file_name)
_validate_remote_host_args(protocol, hostname, username, password)
mgmt_importer = MgmtDataImporter(
parent_mo_or_dn=top_system,
hostname=hostname,
from ..mometa.mgmt.MgmtBackup import MgmtBackup, MgmtBackupConsts
from ..mometa.top.TopSystem import TopSystem
backup_type = "full-state"
if not file_dir:
raise UcscValidationException("Missing file_dir argument")
if not file_name:
raise UcscValidationException("Missing file_name argument")
top_system = TopSystem()
if remote_enabled:
_validate_remote_host_args(protocol, hostname, username, password)
if (not file_name.endswith('.tgz')):
raise UcscValidationException(
"file_name must be .tgz format")
file_path = os.path.join(file_dir, file_name)
mgmt_backup = MgmtBackup(
parent_mo_or_dn=top_system,
hostname=hostname,
admin_state=MgmtBackupConsts.ADMIN_STATE_ENABLED,
proto=protocol,
type=backup_type,
remote_file=file_path,
user=username,
pwd=password)
else:
if not os.path.exists(file_dir):
os.makedirs(file_dir)
from ..mometa.mgmt.MgmtDataExporter import MgmtDataExporter, \
MgmtDataExporterConsts
from ..mometa.top.TopSystem import TopSystem
backup_type = "config-all"
if not file_dir:
raise UcscValidationException("Missing file_dir argument")
if not file_name:
raise UcscValidationException("Missing file_name argument")
top_system = TopSystem()
if remote_enabled:
_validate_remote_host_args(protocol, hostname, username, password)
if (not file_name.endswith('.tgz')):
raise UcscValidationException(
"file_name must be .tgz format")
file_path = os.path.join(file_dir, file_name)
mgmt_export = MgmtDataExporter(
parent_mo_or_dn=top_system,
hostname=hostname,
admin_state=MgmtDataExporterConsts.ADMIN_STATE_ENABLED,
proto=protocol,
type=backup_type,
remote_file=file_path,
user=username,
pwd=password)
else:
if not os.path.exists(file_dir):
os.makedirs(file_dir)
def _validate_remote_host_args(protocol, hostname, username, password):
if not protocol:
raise UcscValidationException("Missing protocol argument")
if not hostname:
raise UcscValidationException("Missing hostname argument")
if protocol == 'tftp':
return
if not username:
raise UcscValidationException("Missing username argument")
if not password:
raise UcscValidationException("Missing password argument")
False - by default
"""
from ..mometa.mgmt.MgmtBackupOperation import MgmtBackupOperation, \
MgmtBackupOperationConsts
from ..mometa.mgmt.MgmtBackup import MgmtBackupConsts
from .ucscdomain import get_domain, _is_domain_available
preserve_pooled_values = False
if not file_dir:
raise UcscValidationException("Missing file_dir argument")
if not file_name:
raise UcscValidationException("Missing file_name argument")
if not domain_ip:
raise UcscValidationException("Missing domain_ip argument")
if backup_type == 'full-state':
if (not file_name.endswith('.tgz')):
raise UcscValidationException(
"file_name must be .tgz format")
elif backup_type == 'config-all':
if (not file_name.endswith('.xml')):
raise UcscValidationException(
"file_name must be .xml format")
_validate_remote_host_args(protocol, hostname, username, password)
domain = get_domain(handle, domain_ip, domain_name)
if _is_domain_available(handle, domain.id):
domain_dn = domain.dn
else:
def _validate_remote_host_args(protocol, hostname, username, password):
if not protocol:
raise UcscValidationException("Missing protocol argument")
if not hostname:
raise UcscValidationException("Missing hostname argument")
if protocol == 'tftp':
return
if not username:
raise UcscValidationException("Missing username argument")
if not password:
raise UcscValidationException("Missing password argument")