Exemplo n.º 1
0
Arquivo: main.py Projeto: anbet/udo
    def get_cluster_and_role_from_args(self, *args):
        args = list(args)
        # need cluster/role
        if len(args) < 1:
            print "Please specify cluster name for this command"
            return None,None,None
        cluster = args.pop(0)

        # use role name if specified, otherwise assume they meant the obvious thing
        # if there's only one role
        if len(args):
            role = args.pop(0)
        else:
            roles = config.get_cluster_config(cluster).get('roles')
            if not roles:
                print "Cluster config for {} not found".format(cluster)
                return None,None,None

            rolenames = roles.keys()
            if len(rolenames) == 1:
                # assume the only role
                print "No role specified, assuming {}".format(rolenames[0])
                role = rolenames[0]
            else:
                print "Multiple roles available for cluster {}".format(cluster)
                for r in rolenames:
                    print "  - {}".format(r)
                return None,None,None

        # still stuff?
        extra = None
        if len(args):
            extra = args.pop(0)

        return cluster, role, extra
Exemplo n.º 2
0
 def __init__(self, cluster_name=None, role_name=None):
     if cluster_name:
         self.cluster_name = cluster_name
         if role_name:
             self.role_name = role_name
             self.cfg = config.get_role_config(cluster_name, role_name)
         else:
             self.cfg = config.get_cluster_config(cluster_name)
     else:
         self.cfg = _cfg.get_root()
     self.conn = util.deploy_conn()
Exemplo n.º 3
0
 def __init__(self, cluster_name=None, role_name=None):
     if cluster_name:
         self.cluster_name = cluster_name
         if role_name:
             self.role_name = role_name
             self.cfg = config.get_role_config(cluster_name, role_name)
         else:
             self.cfg = config.get_cluster_config(cluster_name)
     else:
         self.cfg = _cfg.get_root()
     self.conn = util.deploy_conn()
Exemplo n.º 4
0
    def get_cluster_and_role_from_args(self, arg, quiet=False):
        def fale(msg):
            if not quiet:
                print(msg)
            return None,None

        # need cluster/role
        if not arg:
            return fale("Please specify cluster.role target for this command")
        cluster_role = arg

        help = "Please specify the target of your action using the format: cluster.role"

        cluster_name = None
        role_name = None
        if '.' in cluster_role:
            # split on .
            cluster_name, role_name = cluster_role.split(".")
            if not cluster_name:
                return fale("Cluster name not specified.", help)
            if not role_name:
                return fale("Role name not specified.", help)
        else:
            # assume we're just talking about a cluster with one role
            cluster_name = cluster_role

        cluster = config.get_cluster_config(cluster_name)
        if not cluster:
            return fale("Unknown cluster {}".format(cluster_name))

        roles = cluster.get('roles')
        if not roles:
            return fale("Invalid configuration for {}: no roles are defined".format(cluster_name))

        if not role_name:
            role_names = roles.keys()
            if len(role_names) == 1:
                # assume the only role
                print("No role specified, assuming {}".format(role_names[0]))
                role_name = role_names[0]
            else:
                err = "Multiple roles available for cluster {}".format(cluster_name)
                for r in role_names:
                    err = err + "\n  - {}".format(r)
                return fale(err)

        if not role_name in roles:
            return fale("Role {} not found in cluster {} configuration".format(role_name, cluster_name))

        return cluster_name, role_name
Exemplo n.º 5
0
    def get_cluster_and_role_from_args(self, arg, quiet=False):
        def fale(msg):
            if not quiet:
                print(msg)
            return None,None

        # need cluster/role
        if not arg:
            return fale("Please specify cluster.role target for this command")
        cluster_role = arg

        help = "Please specify the target of your action using the format: cluster.role"

        cluster_name = None
        role_name = None
        if '.' in cluster_role:
            # split on .
            cluster_name, role_name = cluster_role.split(".")
            if not cluster_name:
                return fale("Cluster name not specified.", help)
            if not role_name:
                return fale("Role name not specified.", help)
        else:
            # assume we're just talking about a cluster with one role
            cluster_name = cluster_role

        cluster = config.get_cluster_config(cluster_name)
        if not cluster:
            return fale("Unknown cluster {}".format(cluster_name))

        roles = cluster.get('roles')
        if not roles:
            return fale("Invalid configuration for {}: no roles are defined".format(cluster_name))

        if not role_name:
            role_names = roles.keys()
            if len(role_names) == 1:
                # assume the only role
                print("No role specified, assuming {}".format(role_names[0]))
                role_name = role_names[0]
            else:
                err = "Multiple roles available for cluster {}".format(cluster_name)
                for r in role_names:
                    err = err + "\n  - {}".format(r)
                return fale(err)

        if not role_name in roles:
            return fale("Role {} not found in cluster {} configuration".format(role_name, cluster_name))

        return cluster_name, role_name
Exemplo n.º 6
0
Arquivo: main.py Projeto: joegross/udo
    def get_cluster_and_role_from_args(self, *args):
        args = list(args)
        # need cluster/role
        if len(args) < 1:
            print "Please specify cluster name for this command"
            return None,None,None
        cluster = args.pop(0)

        cluster_config = config.get_cluster_config(cluster)
        if not cluster_config:
            print "Unknown cluster {}".format(cluster)
            return None,None,None

        # use role name if specified, otherwise assume they meant the obvious thing
        # if there's only one role
        if len(args):
            role = args.pop(0)
        else:
            roles = cluster_config.get('roles')
            if not roles:
                print "Cluster config for {} not found".format(cluster)
                return None,None,None

            rolenames = roles.keys()
            if len(rolenames) == 1:
                # assume the only role
                print "No role specified, assuming {}".format(rolenames[0])
                role = rolenames[0]
            else:
                print "Multiple roles available for cluster {}".format(cluster)
                for r in rolenames:
                    print "  - {}".format(r)
                return None,None,None
 
        # still stuff?
        extra = None
        if len(args):
            extra = args.pop(0)

        return cluster, role, extra