def get_cluster(self, cloud_provider=None, config=None, nodes=None):
        if not cloud_provider:
            cloud_provider = BotoCloudProvider("https://hobbes.gc3.uzh.ch/",
                                               "nova", "a-key", "s-key")
        if not config:
            config = Configuration().get_config(self.path)

        setup = Mock()
        configurator = Configurator(config)
        conf_login = configurator.cluster_conf['mycluster']['login']
        repository = PickleRepository(self.storage_path)

        cluster = Cluster(name="mycluster",
                          cloud_provider=cloud_provider,
                          setup_provider=setup,
                          repository=repository,
                          user_key_name=conf_login['user_key_name'],
                          user_key_public=conf_login['user_key_public'],
                          user_key_private=conf_login['user_key_private'],
                          )

        if not nodes:
            nodes = {"compute": 2, "frontend": 1}

        for kind, num in nodes.iteritems():
            conf_kind = configurator.cluster_conf['mycluster']['nodes'][kind]
            cluster.add_nodes(kind, num, conf_kind['image_id'],
                              conf_login['image_user'],
                              conf_kind['flavor'],
                              conf_kind['security_group'])

        return cluster
示例#2
0
    def create_cluster(self, template, name=None):
        """Creates a cluster by inspecting the configuration properties of the
        given cluster template.

        :param str template: name of the cluster template

        :param str name: name of the cluster. If not defined, the cluster
                         will be named after the template.

        :return: :py:class:`elasticluster.cluster.cluster` instance:

        :raises ConfigurationError: cluster template not found in config

        """
        if not name:
            name = template

        if template not in self.cluster_conf:
            raise ConfigurationError(
                "Invalid configuration for cluster `%s`: %s"
                "" % (template, name))

        conf = self.cluster_conf[template]
        conf_login = self.cluster_conf[template]['login']

        extra = conf['cluster'].copy()
        extra.pop('cloud')
        extra.pop('setup_provider')
        extra['template'] = template

        cluster = Cluster(name=name,
                          cloud_provider=self.create_cloud_provider(template),
                          setup_provider=self.create_setup_provider(template, name=name),
                          user_key_name=conf_login['user_key_name'],
                          user_key_public=conf_login['user_key_public'],
                          user_key_private=conf_login["user_key_private"],
                          repository=self.create_repository(),
                          **extra)

        nodes = dict(
            (k[:-6], int(v)) for k, v in conf['cluster'].iteritems() if
            k.endswith('_nodes'))

        for kind, num in nodes.iteritems():
            conf_kind = conf['nodes'][kind]
            extra = conf_kind.copy()
            extra.pop('image_id', None)
            extra.pop('flavor', None)
            extra.pop('security_group', None)
            extra.pop('image_userdata', None)
            userdata = conf_kind.get('image_userdata', '')
            cluster.add_nodes(kind,
                              num,
                              conf_kind['image_id'],
                              conf_login['image_user'],
                              conf_kind['flavor'],
                              conf_kind['security_group'],
                              image_userdata=userdata,
                              **extra)
        return cluster
示例#3
0
    def create_cluster(self, template, name=None):
        """Creates a cluster by inspecting the configuration properties of the
        given cluster template.

        :param str template: name of the cluster template

        :param str name: name of the cluster. If not defined, the cluster
                         will be named after the template.

        :return: :py:class:`elasticluster.cluster.cluster` instance:

        :raises ConfigurationError: cluster template not found in config

        """
        if not name:
            name = template

        if template not in self.cluster_conf:
            raise ConfigurationError(
                "Invalid configuration for cluster `%s`: %s"
                "" % (template, name))

        conf = self.cluster_conf[template]
        conf_login = self.cluster_conf[template]['login']

        extra = conf['cluster'].copy()
        extra.pop('cloud')
        extra.pop('setup_provider')
        extra['template'] = template

        cluster = Cluster(name=name,
                          cloud_provider=self.create_cloud_provider(template),
                          setup_provider=self.create_setup_provider(template,
                                                                    name=name),
                          user_key_name=conf_login['user_key_name'],
                          user_key_public=conf_login['user_key_public'],
                          user_key_private=conf_login["user_key_private"],
                          repository=self.create_repository(),
                          **extra)

        nodes = dict((k[:-6], int(v)) for k, v in conf['cluster'].items()
                     if k.endswith('_nodes'))

        for kind, num in nodes.items():
            conf_kind = conf['nodes'][kind]
            extra = conf_kind.copy()
            extra.pop('image_id', None)
            extra.pop('flavor', None)
            extra.pop('security_group', None)
            extra.pop('image_userdata', None)
            userdata = conf_kind.get('image_userdata', '')
            cluster.add_nodes(kind,
                              num,
                              conf_kind['image_id'],
                              conf_login['image_user'],
                              conf_kind['flavor'],
                              conf_kind['security_group'],
                              image_userdata=userdata,
                              **extra)
        return cluster
示例#4
0
    def get_cluster(self, cloud_provider=None, config=None, nodes=None):
        if not cloud_provider:
            cloud_provider = BotoCloudProvider("https://hobbes.gc3.uzh.ch/",
                                               "nova", "a-key", "s-key")
        if not config:
            config = Configuration().get_config(self.path)

        setup = Mock()
        configurator = Configurator(config)
        conf_login = configurator.cluster_conf['mycluster']['login']
        repository = PickleRepository(self.storage_path)

        cluster = Cluster(
            name="mycluster",
            cloud_provider=cloud_provider,
            setup_provider=setup,
            repository=repository,
            user_key_name=conf_login['user_key_name'],
            user_key_public=conf_login['user_key_public'],
            user_key_private=conf_login['user_key_private'],
        )

        if not nodes:
            nodes = {"compute": 2, "frontend": 1}

        for kind, num in nodes.iteritems():
            conf_kind = configurator.cluster_conf['mycluster']['nodes'][kind]
            cluster.add_nodes(kind, num, conf_kind['image_id'],
                              conf_login['image_user'], conf_kind['flavor'],
                              conf_kind['security_group'])

        return cluster
示例#5
0
    def create_cluster(self, template, name=None, cloud=None, setup=None):
        """
        Creates a ``Cluster``:class: instance by inspecting the configuration
        properties of the given cluster template.

        :param str template: name of the cluster template
        :param str name: name of the cluster. If not defined, the cluster
                         will be named after the template.
        :param cloud: A `CloudProvider`:py:class: instance to use
                      instead of the configured one. If ``None`` (default)
                      then the configured cloud provider will be used.
        :param setup: A `SetupProvider`:py:class: instance to use
                      instead of the configured one. If ``None`` (default)
                      then the configured setup provider will be used.

        :return: :py:class:`elasticluster.cluster.Cluster` instance:

        :raises ConfigurationError: cluster template not found in config
        """
        if template not in self.cluster_conf:
            raise ConfigurationError(
                "No cluster template configuration by the name `{template}`"
                .format(template=template))

        conf = self.cluster_conf[template]

        extra = conf.copy()
        extra.pop('cloud')
        extra.pop('nodes')
        extra.pop('setup')
        extra['template'] = template

        if cloud is None:
            cloud = self.create_cloud_provider(template)
        if name is None:
            name = template
        if setup is None:
            setup = self.create_setup_provider(template, name=name)

        cluster = Cluster(
            name=(name or template),
            cloud_provider=cloud,
            setup_provider=setup,
            user_key_name=conf['login']['user_key_name'],
            user_key_public=conf['login']['user_key_public'],
            user_key_private=conf['login']["user_key_private"],
            repository=self.create_repository(),
            **extra)

        nodes = conf['nodes']
        for group_name in nodes:
            group_conf = nodes[group_name]
            for varname in ['image_user', 'image_userdata']:
                group_conf.setdefault(varname, conf['login'][varname])
            cluster.add_nodes(group_name, **group_conf)
        return cluster
示例#6
0
    def create_cluster(self, template, name=None, cloud=None, setup=None):
        """
        Creates a ``Cluster``:class: instance by inspecting the configuration
        properties of the given cluster template.

        :param str template: name of the cluster template
        :param str name: name of the cluster. If not defined, the cluster
                         will be named after the template.
        :param cloud: A `CloudProvider`:py:class: instance to use
                      instead of the configured one. If ``None`` (default)
                      then the configured cloud provider will be used.
        :param setup: A `SetupProvider`:py:class: instance to use
                      instead of the configured one. If ``None`` (default)
                      then the configured setup provider will be used.

        :return: :py:class:`elasticluster.cluster.Cluster` instance:

        :raises ConfigurationError: cluster template not found in config
        """
        if template not in self.cluster_conf:
            raise ConfigurationError(
                "No cluster template configuration by the name `{template}`"
                .format(template=template))

        conf = self.cluster_conf[template]

        extra = conf.copy()
        extra.pop('cloud')
        extra.pop('nodes')
        extra.pop('setup')
        extra['template'] = template

        if cloud is None:
            cloud = self.create_cloud_provider(template)
        if name is None:
            name = template
        if setup is None:
            setup = self.create_setup_provider(template, name=name)

        cluster = Cluster(
            name=(name or template),
            cloud_provider=cloud,
            setup_provider=setup,
            user_key_name=conf['login']['user_key_name'],
            user_key_public=conf['login']['user_key_public'],
            user_key_private=conf['login']["user_key_private"],
            repository=self.create_repository(),
            **extra)

        nodes = conf['nodes']
        for group_name in nodes:
            group_conf = nodes[group_name]
            for varname in ['image_user', 'image_userdata']:
                group_conf.setdefault(varname, conf['login'][varname])
            cluster.add_nodes(group_name, **group_conf)
        return cluster
示例#7
0
    def get_cluster(self, cloud_provider=None, config=None, nodes=None):
        if not cloud_provider:
            cloud_provider = BotoCloudProvider("https://hobbes.gc3.uzh.ch/", "nova", "a-key", "s-key")
        if not config:
            config = Configuration().get_config(self.path)

        setup = Mock()
        configurator = Configurator(config)
        conf_login = configurator.cluster_conf["mycluster"]["login"]
        repository = PickleRepository(self.storage_path)

        cluster = Cluster(
            "mycluster",
            cloud_provider,
            setup,
            repository,
            conf_login["user_key_name"],
            conf_login["user_key_public"],
            conf_login["user_key_private"],
        )

        if not nodes:
            nodes = {"compute": 2, "frontend": 1}

        for kind, num in nodes.iteritems():
            conf_kind = configurator.cluster_conf["mycluster"]["nodes"][kind]
            cluster.add_nodes(
                kind,
                num,
                conf_kind["image_id"],
                conf_login["image_user"],
                conf_kind["flavor"],
                conf_kind["security_group"],
            )

        return cluster