コード例 #1
0
ファイル: plan.py プロジェクト: lyarwood/tripleo-common
 def run(self, context):
     try:
         swift = self.get_object_client(context)
         # Upload template dir to tmp container
         container_tmp = '%s-tmp' % self.container
         with tempfile.NamedTemporaryFile() as tmp_tarball:
             tarball.create_tarball(self.templates_dir, tmp_tarball.name)
             tarball.tarball_extract_to_swift_container(
                 swift, tmp_tarball.name, container_tmp)
         # Get all new templates:
         new_templates = swift.get_object(container_tmp, '')[1].splitlines()
         old_templates = swift.get_object(self.container,
                                          '')[1].splitlines()
         # Update the old container
         for new in new_templates:
             # if doesn't exist, push it:
             if new not in old_templates:
                 swift.put_object(self.container, new,
                                  swift.get_object(container_tmp, new)[1])
             else:
                 content_new = swift.get_object(container_tmp, new)
                 content_old = swift.get_object(self.container, new)
                 if (not content_new == content_old
                         and constants.PLAN_ENVIRONMENT not in new):
                     swift.put_object(
                         self.container, new,
                         swift.get_object(container_tmp, new)[1])
     except swiftexceptions.ClientException as err:
         msg = "Error attempting an operation on container: %s" % err
         return actions.Result(error=msg)
     except Exception as err:
         msg = "Error while updating plan: %s" % err
         return actions.Result(error=msg)
コード例 #2
0
def _upload_templates(swift_client,
                      container_name,
                      tht_root,
                      roles_file=None,
                      plan_env_file=None,
                      networks_file=None):
    """tarball up a given directory and upload it to Swift to be extracted"""

    with tempfile.NamedTemporaryFile() as tmp_tarball:
        tarball.create_tarball(tht_root, tmp_tarball.name)
        tarball.tarball_extract_to_swift_container(swift_client,
                                                   tmp_tarball.name,
                                                   container_name)

    # Optional override of the roles_data.yaml file
    if roles_file:
        _upload_file(swift_client, container_name,
                     constants.OVERCLOUD_ROLES_FILE,
                     utils.rel_or_abs_path(roles_file, tht_root))

    # Optional override of the network_data.yaml file
    if networks_file:
        _upload_file(swift_client, container_name,
                     constants.OVERCLOUD_NETWORKS_FILE, networks_file)

    # Optional override of the plan-environment.yaml file
    if plan_env_file:
        # TODO(jpalanis): Instead of overriding default file,
        # merging the user override plan-environment with default
        # plan-environment file will avoid explict merging issues.
        _upload_file(swift_client, container_name, constants.PLAN_ENVIRONMENT,
                     plan_env_file)
コード例 #3
0
ファイル: templates.py プロジェクト: larsks/tripleo-common
 def run(self, context):
     with tf.NamedTemporaryFile() as tmp_tarball:
         tarball.create_tarball(self.templates_path, tmp_tarball.name)
         tarball.tarball_extract_to_swift_container(
             self.get_object_client(context),
             tmp_tarball.name,
             self.container)
コード例 #4
0
 def run(self, context):
     with tf.NamedTemporaryFile() as tmp_tarball:
         tarball.create_tarball(self.templates_path, tmp_tarball.name)
         tarball.tarball_extract_to_swift_container(
             self.get_object_client(context),
             tmp_tarball.name,
             self.container)
コード例 #5
0
ファイル: base.py プロジェクト: openstack/tripleo-common
 def run(self, context):
     with tempfile.NamedTemporaryFile() as tmp_tarball:
         tarball.create_tarball(self.dir_to_upload, tmp_tarball.name)
         tarball.tarball_extract_to_swift_container(
             self.get_object_client(context),
             tmp_tarball.name,
             self.container)
コード例 #6
0
def _upload_templates(swift_client, container_name, tht_root):
    """tarball up a given directory and upload it to Swift to be extracted"""

    with tempfile.NamedTemporaryFile() as tmp_tarball:
        tarball.create_tarball(tht_root, tmp_tarball.name)
        tarball.tarball_extract_to_swift_container(swift_client,
                                                   tmp_tarball.name,
                                                   container_name)
コード例 #7
0
ファイル: templates.py プロジェクト: rbrady/tripleo-common
 def run(self):
     tht_base_path = constants.DEFAULT_TEMPLATES_PATH
     with tf.NamedTemporaryFile() as tmp_tarball:
         tarball.create_tarball(tht_base_path, tmp_tarball.name)
         tarball.tarball_extract_to_swift_container(
             self._get_object_client(),
             tmp_tarball.name,
             self.container)
コード例 #8
0
ファイル: plan.py プロジェクト: karelyatin/tripleo-common
 def run(self, context):
     try:
         swift = self.get_object_client(context)
         # Upload template dir to tmp container
         container_tmp = '%s-tmp' % self.container
         with tempfile.NamedTemporaryFile() as tmp_tarball:
             tarball.create_tarball(self.templates_dir, tmp_tarball.name)
             tarball.tarball_extract_to_swift_container(
                 swift,
                 tmp_tarball.name,
                 container_tmp)
         # Get all new templates:
         new_templates = swiftutils.get_object_string(swift, container_tmp,
                                                      '').splitlines()
         old_templates = swiftutils.get_object_string(swift, self.container,
                                                      '').splitlines()
         exclude_user_data = [constants.PLAN_ENVIRONMENT,
                              constants.OVERCLOUD_J2_ROLES_NAME,
                              constants.OVERCLOUD_J2_NETWORKS_NAME,
                              constants.OVERCLOUD_J2_EXCLUDES]
         # Update the old container
         for new in new_templates:
             # if doesn't exist, push it:
             if new not in old_templates:
                 swiftutils.put_object_string(
                     swift,
                     self.container,
                     new,
                     swiftutils.get_object_string(swift, container_tmp, new)
                 )
             else:
                 content_new = swiftutils.get_object_string(swift,
                                                            container_tmp,
                                                            new)
                 content_old = swiftutils.get_object_string(swift,
                                                            self.container,
                                                            new)
                 if (not content_new == content_old and
                    new not in exclude_user_data):
                     swiftutils.put_object_string(
                         swift,
                         self.container,
                         new,
                         swiftutils.get_object_string(swift, container_tmp,
                                                      new)
                     )
     except swiftexceptions.ClientException as err:
         msg = "Error attempting an operation on container: %s" % err
         LOG.exception(msg)
         return actions.Result(error=msg)
     except Exception as err:
         msg = "Error while updating plan: %s" % err
         LOG.exception(msg)
         return actions.Result(error=msg)
コード例 #9
0
def _upload_templates(swift_client, container_name, tht_root, roles_file=None):
    """tarball up a given directory and upload it to Swift to be extracted"""

    with tempfile.NamedTemporaryFile() as tmp_tarball:
        tarball.create_tarball(tht_root, tmp_tarball.name)
        tarball.tarball_extract_to_swift_container(
            swift_client, tmp_tarball.name, container_name)

    # Allow optional override of the roles_data.yaml file
    if roles_file:
        with open(roles_file) as rf:
            swift_client.put_object(container_name,
                                    constants.OVERCLOUD_ROLES_FILE,
                                    rf)
コード例 #10
0
    def run(self, context):
        heat = self.get_orchestration_client(context)
        swift = self.get_object_client(context)

        # Since the config-download directory is now a git repo, first download
        # the existing config container if it exists so we can reuse the
        # existing git repo.
        try:
            swiftutils.download_container(swift, self.container_config,
                                          self.config_dir)
            # Delete the existing container before we re-upload, otherwise
            # files may not be fully overwritten.
            swiftutils.delete_container(swift, self.container_config)
        except swiftexceptions.ClientException as err:
            if err.http_status != 404:
                raise

        # Delete downloaded tarball as it will be recreated later and we don't
        # want to include the old tarball in the new tarball.
        old_tarball_path = os.path.join(self.config_dir,
                                        '%s.tar.gz' % self.container_config)
        if os.path.exists(old_tarball_path):
            os.unlink(old_tarball_path)

        config = ooo_config.Config(heat)
        message = ('Automatic commit by Mistral GetOvercloudConfig action.\n\n'
                   'User: {user}\n'
                   'Project: {project}'.format(user=context.user_name,
                                               project=context.project_name))
        config_path = config.download_config(self.container,
                                             self.config_dir,
                                             self.config_type,
                                             preserve_config_dir=True,
                                             commit_message=message)

        with tempfile.NamedTemporaryFile() as tmp_tarball:
            tarball.create_tarball(config_path,
                                   tmp_tarball.name,
                                   excludes=['.tox', '*.pyc', '*.pyo'])
            tarball.tarball_extract_to_swift_container(
                self.get_object_client(context), tmp_tarball.name,
                self.container_config)
            # Also upload the tarball to the container for use by export later
            with open(tmp_tarball.name, 'rb') as t:
                swift.put_object(self.container_config,
                                 '%s.tar.gz' % self.container_config, t)
        if os.path.exists(config_path):
            shutil.rmtree(config_path)
コード例 #11
0
ファイル: config.py プロジェクト: openstack/tripleo-common
    def run(self, context):
        heat = self.get_orchestration_client(context)
        swift = self.get_object_client(context)

        # Since the config-download directory is now a git repo, first download
        # the existing config container if it exists so we can reuse the
        # existing git repo.
        try:
            swiftutils.download_container(swift, self.container_config,
                                          self.config_dir)
            # Delete the existing container before we re-upload, otherwise
            # files may not be fully overwritten.
            swiftutils.delete_container(swift, self.container_config)
        except swiftexceptions.ClientException as err:
            if err.http_status != 404:
                raise

        # Delete downloaded tarball as it will be recreated later and we don't
        # want to include the old tarball in the new tarball.
        old_tarball_path = os.path.join(
            self.config_dir, '%s.tar.gz' % self.container_config)
        if os.path.exists(old_tarball_path):
            os.unlink(old_tarball_path)

        config = ooo_config.Config(heat)
        message = ('Automatic commit by Mistral GetOvercloudConfig action.\n\n'
                   'User: {user}\n'
                   'Project: {project}'.format(user=context.user_name,
                                               project=context.project_name))
        config_path = config.download_config(self.container, self.config_dir,
                                             self.config_type,
                                             preserve_config_dir=True,
                                             commit_message=message)

        with tempfile.NamedTemporaryFile() as tmp_tarball:
            tarball.create_tarball(config_path, tmp_tarball.name,
                                   excludes=['.tox', '*.pyc', '*.pyo'])
            tarball.tarball_extract_to_swift_container(
                self.get_object_client(context),
                tmp_tarball.name,
                self.container_config)
            # Also upload the tarball to the container for use by export later
            with open(tmp_tarball.name, 'rb') as t:
                swift.put_object(self.container_config,
                                 '%s.tar.gz' % self.container_config, t)
        if os.path.exists(config_path):
            shutil.rmtree(config_path)
コード例 #12
0
ファイル: config.py プロジェクト: pcaruana/tripleo-common
    def run(self, context):
        heat = self.get_orchestration_client(context)
        swift = self.get_object_client(context)

        # Since the config-download directory is now a git repo, first download
        # the existing config container if it exists so we can reuse the
        # existing git repo.
        try:
            swiftutils.download_container(swift, self.container_config,
                                          self.config_dir)
            # Delete the existing container before we re-upload, otherwise
            # files may not be fully overwritten.
            swiftutils.delete_container(swift, self.container_config)
        except swiftexceptions.ClientException as err:
            if err.http_status != 404:
                raise

        config = ooo_config.Config(heat)
        message = ('Automatic commit by Mistral GetOvercloudConfig action.\n\n'
                   'User: {user}\n'
                   'Project: {project}'.format(user=context.user_name,
                                               project=context.project_name))
        config_path = config.download_config(self.container,
                                             self.config_dir,
                                             preserve_config_dir=True,
                                             commit_message=message)

        with tempfile.NamedTemporaryFile() as tmp_tarball:
            tarball.create_tarball(config_path,
                                   tmp_tarball.name,
                                   excludes=['.tox', '*.pyc', '*.pyo'])
            tarball.tarball_extract_to_swift_container(
                self.get_object_client(context), tmp_tarball.name,
                self.container_config)
        if os.path.exists(config_path):
            shutil.rmtree(config_path)
コード例 #13
0
 def run(self, context):
     with tempfile.NamedTemporaryFile() as tmp_tarball:
         tarball.create_tarball(self.dir_to_upload, tmp_tarball.name)
         tarball.tarball_extract_to_swift_container(
             self.get_object_client(context), tmp_tarball.name,
             self.container)
コード例 #14
0
 def run(self):
     tht_base_path = constants.DEFAULT_TEMPLATES_PATH
     with tf.NamedTemporaryFile() as tmp_tarball:
         tarball.create_tarball(tht_base_path, tmp_tarball.name)
         tarball.tarball_extract_to_swift_container(
             self._get_object_client(), tmp_tarball.name, self.container)