def do_bay_config(cs, args):
    """Configure native client to access bay.

    You can source the output of this command to get the native client of the
    corresponding COE configured to access the bay.

    Example: eval $(magnum bay-config <bay-name>).

    (Deprecated in favor of cluster-config.)
    """
    args.dir = os.path.abspath(args.dir)
    bay = cs.bays.get(args.bay)
    if bay.status not in ('CREATE_COMPLETE', 'UPDATE_COMPLETE'):
        raise exceptions.CommandError("Bay in status %s" % bay.status)
    baymodel = cs.baymodels.get(bay.baymodel_id)
    opts = {
        'cluster_uuid': bay.uuid,
    }

    if not baymodel.tls_disabled:
        tls = magnum_utils.generate_csr_and_key()
        tls['ca'] = cs.certificates.get(**opts).pem
        opts['csr'] = tls['csr']
        tls['cert'] = cs.certificates.create(**opts).pem
        for k in ('key', 'cert', 'ca'):
            fname = "%s/%s.pem" % (args.dir, k)
            if os.path.exists(fname) and not args.force:
                raise Exception("File %s exists, aborting." % fname)
            else:
                f = open(fname, "w")
                f.write(tls[k])
                f.close()

    print(magnum_utils.config_cluster(bay, baymodel, cfg_dir=args.dir,
                                      force=args.force))
    def take_action(self, parsed_args):
        """Configure native client to access cluster.

        You can source the output of this command to get the native client of
        the corresponding COE configured to access the cluster.

        """
        if parsed_args.use_keystone:
            parsed_args.use_certificate = False
        if not parsed_args.use_certificate:
            parsed_args.use_keystone = True

        self.log.debug("take_action(%s)", parsed_args)

        mag_client = self.app.client_manager.container_infra

        parsed_args.dir = os.path.abspath(parsed_args.dir)
        cluster = mag_client.clusters.get(parsed_args.cluster)
        if cluster.api_address is None:
            self.log.warning("WARNING: The cluster's api_address is"
                             " not known yet.")

        cluster_template = mag_client.cluster_templates.get(
            cluster.cluster_template_id)
        opts = {
            'cluster_uuid': cluster.uuid,
        }

        tls = None
        if not cluster_template.tls_disabled:
            tls = magnum_utils.generate_csr_and_key()
            tls['ca'] = mag_client.certificates.get(**opts).pem
            opts['csr'] = tls['csr']
            tls['cert'] = mag_client.certificates.create(**opts).pem
            if parsed_args.output_certs:
                for k in ('key', 'cert', 'ca'):
                    fname = "%s/%s.pem" % (parsed_args.dir, k)
                    if os.path.exists(fname) and not parsed_args.force:
                        raise Exception("File %s exists, aborting." % fname)
                    else:
                        with open(fname, "w") as f:
                            f.write(tls[k])

        print(
            magnum_utils.config_cluster(cluster,
                                        cluster_template,
                                        parsed_args.dir,
                                        force=parsed_args.force,
                                        certs=tls,
                                        use_keystone=parsed_args.use_keystone))
Exemple #3
0
    def take_action(self, parsed_args):
        """Configure native client to access cluster.

        You can source the output of this command to get the native client of
        the corresponding COE configured to access the cluster.

        """
        self.log.debug("take_action(%s)", parsed_args)

        mag_client = self.app.client_manager.container_infra

        parsed_args.dir = os.path.abspath(parsed_args.dir)
        cluster = mag_client.clusters.get(parsed_args.cluster)
        if cluster.status not in ('CREATE_COMPLETE', 'UPDATE_COMPLETE',
                                  'ROLLBACK_COMPLETE'):
            raise exceptions.CommandError("cluster in status %s" %
                                          cluster.status)
        cluster_template = mag_client.cluster_templates.get(
            cluster.cluster_template_id)
        opts = {
            'cluster_uuid': cluster.uuid,
        }

        if not cluster_template.tls_disabled:
            tls = magnum_utils.generate_csr_and_key()
            tls['ca'] = mag_client.certificates.get(**opts).pem
            opts['csr'] = tls['csr']
            tls['cert'] = mag_client.certificates.create(**opts).pem
            for k in ('key', 'cert', 'ca'):
                fname = "%s/%s.pem" % (parsed_args.dir, k)
                if os.path.exists(fname) and not parsed_args.force:
                    raise Exception("File %s exists, aborting." % fname)
                else:
                    f = open(fname, "w")
                    f.write(tls[k])
                    f.close()

        print(
            magnum_utils.config_cluster(cluster,
                                        cluster_template,
                                        parsed_args.dir,
                                        force=parsed_args.force))
def do_bay_config(cs, args):
    """Configure native client to access bay.

    You can source the output of this command to get the native client of the
    corresponding COE configured to access the bay.

    Example: eval $(magnum bay-config <bay-name>).

    (Deprecated in favor of cluster-config.)
    """
    args.dir = os.path.abspath(args.dir)
    bay = cs.bays.get(args.bay)
    if bay.status not in ('CREATE_COMPLETE', 'UPDATE_COMPLETE'):
        raise exceptions.CommandError("Bay in status %s" % bay.status)
    baymodel = cs.baymodels.get(bay.baymodel_id)
    opts = {
        'cluster_uuid': bay.uuid,
    }

    if not baymodel.tls_disabled:
        tls = magnum_utils.generate_csr_and_key()
        tls['ca'] = cs.certificates.get(**opts).pem
        opts['csr'] = tls['csr']
        tls['cert'] = cs.certificates.create(**opts).pem
        for k in ('key', 'cert', 'ca'):
            fname = "%s/%s.pem" % (args.dir, k)
            if os.path.exists(fname) and not args.force:
                raise Exception("File %s exists, aborting." % fname)
            else:
                f = open(fname, "w")
                f.write(tls[k])
                f.close()

    print(
        magnum_utils.config_cluster(bay,
                                    baymodel,
                                    cfg_dir=args.dir,
                                    force=args.force))
Exemple #5
0
def do_cluster_config(cs, args):
    """Configure native client to access cluster.

    You can source the output of this command to get the native client of the
    corresponding COE configured to access the cluster.

    Example: eval $(magnum cluster-config <cluster-name>).
    """
    args.dir = os.path.abspath(args.dir)
    cluster = cs.clusters.get(args.cluster)
    if cluster.status not in ('CREATE_COMPLETE', 'UPDATE_COMPLETE',
                              'ROLLBACK_COMPLETE'):
        raise exceptions.CommandError("cluster in status %s" % cluster.status)
    cluster_template = cs.cluster_templates.get(cluster.cluster_template_id)
    opts = {
        'cluster_uuid': cluster.uuid,
    }

    if not cluster_template.tls_disabled:
        tls = magnum_utils.generate_csr_and_key()
        tls['ca'] = cs.certificates.get(**opts).pem
        opts['csr'] = tls['csr']
        tls['cert'] = cs.certificates.create(**opts).pem
        for k in ('key', 'cert', 'ca'):
            fname = "%s/%s.pem" % (args.dir, k)
            if os.path.exists(fname) and not args.force:
                raise Exception("File %s exists, aborting." % fname)
            else:
                f = open(fname, "w")
                f.write(tls[k])
                f.close()

    print(
        magnum_utils.config_cluster(cluster,
                                    cluster_template,
                                    cfg_dir=args.dir,
                                    force=args.force))
Exemple #6
0
def do_cluster_config(cs, args):
    """Configure native client to access cluster.

    You can source the output of this command to get the native client of the
    corresponding COE configured to access the cluster.

    Example: eval $(magnum cluster-config <cluster-name>).
    """
    args.dir = os.path.abspath(args.dir)
    cluster = cs.clusters.get(args.cluster)
    if (hasattr(cluster, 'api_address') and cluster.api_address is None):
        print("WARNING: The cluster's api_address is not known yet.")
    cluster_template = cs.cluster_templates.get(cluster.cluster_template_id)
    opts = {
        'cluster_uuid': cluster.uuid,
    }

    if not cluster_template.tls_disabled:
        tls = magnum_utils.generate_csr_and_key()
        tls['ca'] = cs.certificates.get(**opts).pem
        opts['csr'] = tls['csr']
        tls['cert'] = cs.certificates.create(**opts).pem
        for k in ('key', 'cert', 'ca'):
            fname = "%s/%s.pem" % (args.dir, k)
            if os.path.exists(fname) and not args.force:
                raise Exception("File %s exists, aborting." % fname)
            else:
                f = open(fname, "w")
                f.write(tls[k])
                f.close()

    print(
        magnum_utils.config_cluster(cluster,
                                    cluster_template,
                                    cfg_dir=args.dir,
                                    force=args.force))