Exemplo n.º 1
0
    def provision(self):
        self.status = ClusterStatus.PROVISIONING

        base_url = getApiUrl()
        log_write_url = '%s/clusters/%s/log' % (base_url, self.cluster['_id'])
        girder_token = get_task_token()['_id']

        profile, secret_key = _get_profile(self.cluster['profileId'])

        playbook = get_property(
            'config.provision.spec', self.cluster,
            default=self.DEFAULT_PLAYBOOK)
        playbook_params = get_property(
            'config.provision.params', self.cluster, default={})
        provision_ssh_user = get_property(
            'config.provision.ssh.user', self.cluster, default='ubuntu')
        playbook_params['cluster_state'] = ClusterStatus.RUNNING
        playbook_params['ansible_ssh_user'] = provision_ssh_user

        cumulus.ansible.tasks.cluster.provision_cluster \
            .delay(playbook,
                   self._model.filter(self.cluster, getCurrentUser(), passphrase=False),
                   profile, secret_key, playbook_params,
                   girder_token, log_write_url, ClusterStatus.RUNNING)

        return self.cluster
Exemplo n.º 2
0
    def provision(self):
        self.status = ClusterStatus.PROVISIONING

        base_url = cumulus.config.girder.baseUrl
        log_write_url = '%s/clusters/%s/log' % (base_url, self.cluster['_id'])
        girder_token = get_task_token()['_id']

        profile, secret_key = _get_profile(self.cluster['profileId'])

        playbook = get_property('config.provision.spec',
                                self.cluster,
                                default=self.DEFAULT_PLAYBOOK)
        playbook_params = get_property('config.provision.params',
                                       self.cluster,
                                       default={})
        provision_ssh_user = get_property('config.provision.ssh.user',
                                          self.cluster,
                                          default='ubuntu')
        playbook_params['cluster_state'] = ClusterStatus.RUNNING
        playbook_params['ansible_ssh_user'] = provision_ssh_user

        cumulus.ansible.tasks.cluster.provision_cluster \
            .delay(playbook,
                   self._model.filter(self.cluster, getCurrentUser(), passphrase=False),
                   profile, secret_key, playbook_params,
                   girder_token, log_write_url, ClusterStatus.RUNNING)

        return self.cluster
Exemplo n.º 3
0
    def _create_ansible(self, params, body, cluster_type=ClusterType.ANSIBLE):

        self.requireParams(['name', 'profileId'], body)

        name = body['name']
        playbook = get_property('config.launch.spec', body, default='default')
        launch_params = get_property('config.launch.params', body, default={})
        profile_id = body['profileId']
        user = self.getCurrentUser()

        cluster = self._model.create_ansible(user, name, playbook,
                                             launch_params, profile_id,
                                             cluster_type=cluster_type)

        return cluster
Exemplo n.º 4
0
    def provision(self, cluster, params):

        if not ClusterStatus.valid_transition(cluster['status'],
                                              ClusterStatus.PROVISIONING):
            raise RestException(
                'Cluster status is %s and cannot be provisioned' %
                cluster['status'],
                code=400)

        body = self._get_body()
        provision_ssh_user = get_property('ssh.user', body)
        if provision_ssh_user:
            cluster['config'].setdefault('provision', {})['ssh'] = {
                'user': provision_ssh_user
            }
            del body['ssh']

        if 'spec' in body:
            cluster['config'].setdefault('provision', {})['spec'] \
                = body['spec']
            del body['spec']

        cluster['config'].setdefault('provision', {})\
            .setdefault('params', {}).update(body)
        cluster = self._model.save(cluster)

        return self._model.filter(
            self._launch_or_provision('provision', cluster),
            self.getCurrentUser())
Exemplo n.º 5
0
    def provision(self, cluster, params):

        if not ClusterStatus.valid_transition(
                cluster['status'], ClusterStatus.PROVISIONING):
            raise RestException(
                'Cluster status is %s and cannot be provisioned' %
                cluster['status'], code=400)

        body = self._get_body()
        provision_ssh_user = get_property('ssh.user', body)
        if provision_ssh_user:
            cluster['config'].setdefault('provision', {})['ssh'] = {
                'user': provision_ssh_user
            }
            del body['ssh']

        if 'spec' in body:
            cluster['config'].setdefault('provision', {})['spec'] \
                = body['spec']
            del body['spec']

        cluster['config'].setdefault('provision', {})\
            .setdefault('params', {}).update(body)
        cluster = self._model.save(cluster)

        return self._model.filter(
            self._launch_or_provision('provision', cluster),
            self.getCurrentUser())
Exemplo n.º 6
0
    def _create_ansible(self, params, body, cluster_type=ClusterType.ANSIBLE):

        self.requireParams(['name', 'profileId'], body)

        name = body['name']
        playbook = get_property('config.launch.spec', body, default='default')
        launch_params = get_property('config.launch.params', body, default={})
        config = get_property('config', body, default={})
        profile_id = body['profileId']
        user = self.getCurrentUser()

        cluster = self._model.create_ansible(user, name, config, playbook,
                                             launch_params, profile_id,
                                             cluster_type=cluster_type)

        return cluster
Exemplo n.º 7
0
    def start(self, request_body):
        """
        Adapters may implement this if they support a start operation.
        """

        self.status = ClusterStatus.LAUNCHING

        self.cluster['config'].setdefault('provision', {})\
            .setdefault('params', {}).update(request_body)
        self.cluster = self.model('cluster', 'cumulus').save(self.cluster)

        base_url = cumulus.config.girder.baseUrl
        log_write_url = '%s/clusters/%s/log' % (base_url, self.cluster['_id'])
        girder_token = get_task_token()['_id']
        profile, secret_key = _get_profile(self.cluster['profileId'])

        # Launch
        launch_playbook = get_property('config.launch.spec',
                                       self.cluster,
                                       default=self.DEFAULT_PLAYBOOK)
        launch_playbook_params = get_property('config.launch.params',
                                              self.cluster,
                                              default={})
        launch_playbook_params['cluster_state'] = ClusterStatus.RUNNING

        # Provision
        provision_playbook = get_property('config.provision.spec',
                                          self.cluster,
                                          default='gridengine/site')
        provision_playbook_params = get_property('config.provision.params',
                                                 self.cluster,
                                                 default={})
        provision_ssh_user = get_property('config.provision.ssh.user',
                                          self.cluster,
                                          default='ubuntu')
        provision_playbook_params['ansible_ssh_user'] = provision_ssh_user
        provision_playbook_params['cluster_state'] = ClusterStatus.RUNNING

        cumulus.ansible.tasks.cluster.start_cluster \
            .delay(launch_playbook,
                   # provision playbook
                   provision_playbook,
                   self._model.filter(self.cluster, getCurrentUser(), passphrase=False),
                   profile, secret_key,
                   launch_playbook_params, provision_playbook_params,
                   girder_token, log_write_url)
Exemplo n.º 8
0
    def terminate(self):
        self.status = ClusterStatus.TERMINATING

        base_url = getApiUrl()
        log_write_url = '%s/clusters/%s/log' % (base_url, self.cluster['_id'])
        girder_token = get_task_token()['_id']

        profile, secret_key = _get_profile(self.cluster['profileId'])

        playbook = get_property(
            'config.launch.spec', self.cluster, default=self.DEFAULT_PLAYBOOK)
        playbook_params = get_property(
            'config.launch.params', self.cluster, default={})
        playbook_params['cluster_state'] = 'absent'

        cumulus.ansible.tasks.cluster.terminate_cluster \
            .delay(playbook,
                   self._model.filter(self.cluster, getCurrentUser(), passphrase=False),
                   profile, secret_key, playbook_params, girder_token,
                   log_write_url, ClusterStatus.TERMINATED)
Exemplo n.º 9
0
    def start(self, request_body):
        """
        Adapters may implement this if they support a start operation.
        """

        self.status = ClusterStatus.LAUNCHING

        self.cluster['config'].setdefault('provision', {})\
            .setdefault('params', {}).update(request_body)
        self.cluster = self.model('cluster', 'cumulus').save(self.cluster)

        base_url = getApiUrl()
        log_write_url = '%s/clusters/%s/log' % (base_url, self.cluster['_id'])
        girder_token = get_task_token()['_id']
        profile, secret_key = _get_profile(self.cluster['profileId'])

        # Launch
        launch_playbook = get_property(
            'config.launch.spec', self.cluster, default=self.DEFAULT_PLAYBOOK)
        launch_playbook_params = get_property(
            'config.launch.params', self.cluster, default={})
        launch_playbook_params['cluster_state'] = ClusterStatus.RUNNING

        # Provision
        provision_playbook = get_property(
            'config.provision.spec', self.cluster, default='gridengine/site')
        provision_playbook_params = get_property(
            'config.provision.params', self.cluster, default={})
        provision_ssh_user = get_property(
            'config.provision.ssh.user', self.cluster, default='ubuntu')
        provision_playbook_params['ansible_ssh_user'] = provision_ssh_user
        provision_playbook_params['cluster_state'] = ClusterStatus.RUNNING

        cumulus.ansible.tasks.cluster.start_cluster \
            .delay(launch_playbook,
                   # provision playbook
                   provision_playbook,
                   self._model.filter(self.cluster, getCurrentUser(), passphrase=False),
                   profile, secret_key,
                   launch_playbook_params, provision_playbook_params,
                   girder_token, log_write_url)
Exemplo n.º 10
0
    def terminate(self):
        self.status = ClusterStatus.TERMINATING

        base_url = cumulus.config.girder.baseUrl
        log_write_url = '%s/clusters/%s/log' % (base_url, self.cluster['_id'])
        girder_token = get_task_token()['_id']

        profile, secret_key = _get_profile(self.cluster['profileId'])

        playbook = get_property('config.launch.spec',
                                self.cluster,
                                default=self.DEFAULT_PLAYBOOK)
        playbook_params = get_property('config.launch.params',
                                       self.cluster,
                                       default={})
        playbook_params['cluster_state'] = 'absent'

        cumulus.ansible.tasks.cluster.terminate_cluster \
            .delay(playbook,
                   self._model.filter(self.cluster, getCurrentUser(), passphrase=False),
                   profile, secret_key, playbook_params, girder_token,
                   log_write_url, ClusterStatus.TERMINATED)
Exemplo n.º 11
0
def retrieve_credentials(event):
    cluster_id = event.info['authKey']
    user = event.info['user']
    model = ModelImporter.model('cluster', 'cumulus')
    cluster = model.load(cluster_id, user=getCurrentUser(),
                         level=AccessType.READ)
    event.stopPropagation()

    if not cluster:
        return

    username = parse('config.ssh.user').find(cluster)[0].value
    key_name = parse('config.ssh.key').find(cluster)[0].value
    key_path = os.path.join(cumulus.config.ssh.keyStore, key_name)
    passphrase = get_property('config.ssh.passphrase', cluster)

    if user != username:
        raise Exception('User doesn\'t match cluster user id ')

    event.addResponse((key_path, passphrase))
Exemplo n.º 12
0
def retrieve_credentials(event):
    cluster_id = event.info['authKey']
    user = event.info['user']
    model = ModelImporter.model('cluster', 'cumulus')
    cluster = model.load(cluster_id,
                         user=getCurrentUser(),
                         level=AccessType.READ)
    event.stopPropagation()

    if not cluster:
        return

    username = parse('config.ssh.user').find(cluster)[0].value
    key_name = parse('config.ssh.key').find(cluster)[0].value
    key_path = os.path.join(cumulus.config.ssh.keyStore, key_name)
    passphrase = get_property('config.ssh.passphrase', cluster)

    if user != username:
        raise Exception('User doesn\'t match cluster user id ')

    event.addResponse((key_path, passphrase))