示例#1
0
def main():
    """Main program"""
    # Fabric-specific variables are wrapped into an object for convenience
    fc = fabricconf()

    # Default variables
    threads = 1
    provider = "ec2"
    role = "client"
    instances = 0
    fc.task = "setup_client"
    remote = None
    peer = None

    # Load configuration settings from ssh.conf. Anything given on the
    # command-line will override these.
    try:
        sshconfig = ConfigParser.RawConfigParser()
        sshfilename = "config/ssh.conf"
        sshconfig.readfp(open(sshfilename))
    except IOError:
        pass

    authdetails = {}
    for i in ["username", "keyfile", "password"]:
        try:
            authdetails[i] = sshconfig.get("ssh", i)
        except:
            authdetails[i] = None

    fc.username = authdetails["username"]
    fc.keyfile = authdetails["keyfile"]
    fc.password = authdetails["password"]

    # Parse command-line arguments
    try:
        # Arguments that are followed by a : require a value
        opts, args = getopt.getopt(sys.argv[1:], "hu:p:k:o:r:a:i:t:m:e:",\
["help", "username="******"password="******"keyfile=", "provider=",\
"role=", "task=", "instances=", "threads=", "remote=", "peer="])
    except getopt.GetoptError:
        Usage()
        sys.exit(1)

    for o, a in opts:
        if o in ("-h", "--help"):
            Usage()
        if o in ("-u", "--username"):
            fc.username = a
        if o in ("-p", "--password"):
            fc.password = a
        if o in ("-k", "--keyfile"):
            fc.keyfile = a
        if o in ("-o", "--provider"):
            provider = a
        if o in ("-t", "--threads"):
            threads = int(a)
        if o in ("-r", "--role"):
            role = a
        if o in ("-a", "--task"):
            fc.task = a
        if o in ("-i", "--instances"):
            instances = int(a)
        if o in ("-m", "--remote"):
            remote = a
        if o in ("-e", "--peer"):
            peer = a

    if remote is not None and peer is not None:
        create_testsuite(remote, peer)

    # FIXME: implement dynamic peer definitions in tests
    #if peer is None:
    #	print "Option \"peer\" missing!"
    #	Usage()

    # Launch the provider thread
    if provider == "ec2":
        launchthr = launch_ec2(fc.keyfile, role, instances)
    elif provider == "test":
        print "ERROR: test provider only partially implemented"
        sys.exit(1)
    else:
        print "Skipping provisioning as requested."

    # Launch configurer threads
    if threads == 0:
        print "No configurer threads, skipping configuration part."
    else:
        for id in range(0, threads):
            configthr = configurer(id, fc, launchthr.queue)
            configthr.setDaemon(False)
            configthr.start()
    sys.exit(0)
示例#2
0
from interpretor import interpretor
from configurer import configurer
from evaluator import evaluator
from admin import admin

itp=interpretor('localhost',27017)
config=configurer(itp)
eva=evaluator(itp)
ad=admin(eva,config)




"""This script performs a complete test of our Python+MongoDB OrBAC single Tenant implementation"""

"""Test Scenario
1. we start from zero having a tenant called "apple"
2. we insert all administrative views including: srole,activity,view,role_assignment,activity_assignment,licence,cross_licence
3. we initialize it with assigning "John" to subject, "admin" to role, insert delete to action, insertActivity, deleteActivity and manage to activity and the first licence " John is permitted to manage licence in apple, also "nominal" to context
4. we then use John to create licences for himself for all administrative views, then use John to create different users,actions, resources and assign them to different abstract roles,activities,views
5. use John to assign users privileges
6. use John to assign admin privileges to someone
"""
"""1. we start from zero having a tenant called apple"""
#create tenant
config.CreateTenant('null','apple')
"""2. we insert all administrative views including: subject,action,object,role,activity,view,role_assignment,activity_assignment,licence
"""
#create administrative views
config.AssignView('null','apple',{'_id':'context','attr':{}})
config.AssignView('null','apple',{'_id':'role','attr':{}})
示例#3
0
文件: start.py 项目: mattock/perftest
def main():
	"""Main program"""
	# Fabric-specific variables are wrapped into an object for convenience
	fc = fabricconf()

	# Default variables
	threads = 1
	provider = "ec2"
	role = "client"
	instances = 0
	fc.task = "setup_client"
	remote = None
	peer = None

	# Load configuration settings from ssh.conf. Anything given on the 
	# command-line will override these.
	try:
		sshconfig = ConfigParser.RawConfigParser()
		sshfilename = "config/ssh.conf"
		sshconfig.readfp(open(sshfilename))
	except IOError:
		pass

	authdetails = {}
	for i in ["username","keyfile","password"]:
		try:
			authdetails[i] = sshconfig.get("ssh",i)
		except:
			authdetails[i] = None

	fc.username = authdetails["username"]
	fc.keyfile = authdetails["keyfile"]
	fc.password = authdetails["password"]

	# Parse command-line arguments
	try:
		# Arguments that are followed by a : require a value
                opts, args = getopt.getopt(sys.argv[1:], "hu:p:k:o:r:a:i:t:m:e:",\
		["help", "username="******"password="******"keyfile=", "provider=",\
		"role=", "task=", "instances=", "threads=", "remote=", "peer="])
        except getopt.GetoptError:
                Usage()
                sys.exit(1)

        for o, a in opts:
                if o in ("-h","--help"):
                        Usage()
                if o in ("-u", "--username"):
			fc.username = a
                if o in ("-p", "--password"): 
                        fc.password = a
                if o in ("-k", "--keyfile"):
                        fc.keyfile = a
                if o in ("-o", "--provider"):
                        provider = a
		if o in ("-t", "--threads"):
			threads = int(a)
                if o in ("-r", "--role"):
                        role = a
                if o in ("-a", "--task"):
                        fc.task = a
                if o in ("-i", "--instances"):
                        instances = int(a)
                if o in ("-m", "--remote"):
			remote = a
                if o in ("-e", "--peer"):
			peer = a

	if remote is not None and peer is not None:
		create_testsuite(remote,peer)

	# FIXME: implement dynamic peer definitions in tests
	#if peer is None:
	#	print "Option \"peer\" missing!"
	#	Usage()


	# Launch the provider thread
	if provider == "ec2":
		launchthr = launch_ec2(fc.keyfile,role,instances)
	elif provider == "test":
		print "ERROR: test provider only partially implemented"
		sys.exit(1)
	else:
		print "Skipping provisioning as requested."

	# Launch configurer threads
	if threads == 0:
		print "No configurer threads, skipping configuration part."
	else:
		for id in range(0,threads):
			configthr = configurer(id,fc,launchthr.queue)
			configthr.setDaemon(False)
			configthr.start()
	sys.exit(0)