本文整理汇总了Python中device.Device.is_current_node_active方法的典型用法代码示例。如果您正苦于以下问题:Python Device.is_current_node_active方法的具体用法?Python Device.is_current_node_active怎么用?Python Device.is_current_node_active使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类device.Device
的用法示例。
在下文中一共展示了Device.is_current_node_active方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import is_current_node_active [as 别名]
def main():
parser = ArgumentParser(description="F5 Deployer")
parser.add_argument('obj', action='store', help="The object you want to "
"work with. pool|virutal_server|node")
parser.add_argument('action', action='store', help='list, create')
parser.add_argument('--user', action="store", dest="username",
default=getpass.getuser(), required=False,
help="Rackspace SSO username. Defaults to current "
"user.")
parser.add_argument('--password', action="store", dest="password",
required=False, help="Username. Defaults "
"to current user.")
parser.add_argument('--host', action="store", dest="host", required=True,
help='FQDN of the LB you are targeting')
parser.add_argument('--partition', action="store", dest="partition",
default="Common", required=False,
help='The target partition. Defaults to Common')
args, unknown = parser.parse_known_args()
if args.password is None:
print ("Enter Password")
password = getpass.getpass()
else:
password = args.password
if args.obj not in ["pool", "virtual_server", "node", "ssl_file", "ssl_profile", "profile"]:
print "Please specify a valid object. pool|virtual_server|node"
raise Exception("Invalid object specified: {}".format(args.obj))
if args.action not in ["list", "create", "delete"]:
print "Please specify a valid action. list|create, delete"
raise Exception("Invalid action specified: {}".format(args.action))
connection = get_f5_connection(args.host, args.username, password, args.partition)
if connection is False:
raise Exception("Unable to get F5 connection")
device = Device(connection)
if device.is_current_node_active(args.host, args.partition) == True:
##### This call only works in F5 1.4<
#if client:
# print device.get_config_sync_status()
object_connection = get_object_connection(args.obj, connection,
args.partition, parser)
if args.action == "list":
print object_connection.list()
elif args.action == "create":
result = object_connection.create(parser)
if result == True:
print "Added {} Succesfully".format(args.obj)
print device.sync_to_group()
else:
print "Error, operation did not succeed"
elif args.action == "delete":
result = object_connection.delete(parser)
if result == True:
print "Deleted {} Succesfully".format(args.obj)
print device.sync_to_group()
else:
print "Error, operation did not succeed"
else:
print "The device you connected to is NOT THE MASTER"
print ("The master is currenlty %s") % (device.get_active_node())
raise Exception("Specified host is not the master")
示例2: main
# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import is_current_node_active [as 别名]
def main():
parser = ArgumentParser(description="F5 Deployer")
parser.add_argument('obj', action='store', metavar='object_type',
choices=objects,
help='Object type. One of %(choices)s.')
parser.add_argument('action', action='store', metavar='action',
choices=actions,
help='Action. One of %(choices)s.')
parser.add_argument('--formatter', action='store', metavar='formatter',
choices=ListFormatters.keys(),
default='columns',
help='Output format for lists. One of %(choices)s.')
parser.add_argument('--user', action="store", dest="user",
required=False,
help="User name. Defaults to current user.")
parser.add_argument('--password', action="store", dest="password",
help="Password")
parser.add_argument('--verify', dest='verify', action='store_true',
help='Do SSL cert validation')
parser.add_argument('--no-verify', dest='verify', action='store_false',
help='Do not do SSL cert validation')
parser.set_defaults(verify=None)
parser.add_argument('--host', action="store", dest="host",
help='FQDN of the LB you are targeting')
parser.add_argument('--partition', action="store", dest="partition",
default="Common", required=False,
help='The target partition. Defaults to Common')
parser.add_argument('--strip-prefix', action="store", dest="strip_prefix",
default="/Common/", required=False,
help='Prefix to strip off each item in list')
args, unknown = parser.parse_known_args()
config = get_config()
host = args.host or config.get('defaults', 'host')
user = args.user or config.get(host, 'user')
password = args.password or config.get(host, 'password')
verify = args.verify
if verify is None:
verify = config.getboolean(host, 'verify')
if password is None:
prompt = 'Password for {user}@{host}: '.format(user=user, host=host)
password = getpass.getpass(prompt)
connection = get_f5_connection(
host, user, password, args.partition,
debug=True, verify=verify)
if not connection:
raise Exception("Unable to get F5 connection")
device = Device(connection)
if device.is_current_node_active(args.partition):
# This call only works in F5 1.4<
# if client:
# print device.get_config_sync_status()
object_connection = get_object_connection(args.obj, connection,
args.partition, parser)
if args.action == "list":
obj_list = []
for item in object_connection.list():
if item.startswith(args.strip_prefix):
item = item[len(args.strip_prefix):]
obj_list.append(item)
formatter = ListFormatters.get(args.formatter)
print(formatter(obj_list))
elif args.action == "list-members":
obj_list = []
for item in object_connection.list_members():
if item['address'].startswith(args.strip_prefix):
item['address'] = item['address'][len(args.strip_prefix):]
node = '{}:{}'.format(item['address'], item['port'])
obj_list.append(node)
formatter = ListFormatters.get(args.formatter)
print(formatter(obj_list))
elif args.action == "create":
result = object_connection.create(parser)
if result:
print("Added {} Succesfully".format(args.obj))
print(device.sync_to_group())
else:
print("Error, operation did not succeed")
elif args.action == "delete":
result = object_connection.delete(parser)
if result:
print("Deleted {} Succesfully".format(args.obj))
print(device.sync_to_group())
else:
print("Error, operation did not succeed")
else:
print("The device you connected to is NOT THE MASTER")
print("The master is currently %s") % (device.get_active_node())
raise Exception("Specified host is not the master")