Exemplo n.º 1
0
    def create(cls, env, group):
        """
        Creates, provisions, and saves a new host.

        :Parameters:
          - `env`: the host's environment.
          - `group`: the host's group.
        """
        domain_name = env.system.domain_name
        hostname = utils.generate_random_hex(8)
        fqdn = '%s.%s' % (hostname, domain_name) if domain_name else hostname

        host = cls(fqdn=fqdn,
                   name=fqdn,
                   hostname=hostname,
                   domain_name=domain_name,
                   environment=env,
                   group=group)

        if not env.backend:
            raise exceptions.UndefinedBackend()
        host.address = env.backend.create_host(host)
        host.finish_provisioning()
        host.save()
        log.info('Creating new instance for host...')
        host.create_instance(group.node)

        return host
Exemplo n.º 2
0
    def create(cls, path, system):
        """
        Creates, and processes, and archives a release. Emits a
        `release_created` signal upon completion.

        :Parameters:
          - `path`: the path to create the release from.
          - `system`: the system to associate the release with.
        """
        release = cls(
            name=utils.generate_memorable_name(),
            sha=utils.generate_random_hex(28),
            system=system
        )

        # Copy to temporary directory
        tmp_path = utils.temp_dir(path)

        # Create snapshot
        snapshot = parser.Snapshot(tmp_path)

        # Build release from snapshot
        # Archive the release
        utils.clear_path(release.data_dir)

        # Tar release buffer
        tar_path = os.path.join(release.data_dir, cls.archive_name)
        tar_file = tarfile.open(tar_path, 'w:gz')
        tar_file.add(tmp_path, '/')
        tar_file.close()

        # Build docker images
        snapshot.build_and_push(release, system)

        # Delete snapshot buffer
        utils.delete_path(tmp_path)

        # Build finished
        release.save()
        signals.release_created.send(sender=release)
        return release
Exemplo n.º 3
0
    def create(cls, path, system):
        """
        Creates, and processes, and archives a release. Emits a
        `release_created` signal upon completion.

        :Parameters:
          - `path`: the path to create the release from.
          - `system`: the system to associate the release with.
        """
        release = cls(name=utils.generate_memorable_name(),
                      sha=utils.generate_random_hex(28),
                      system=system)

        # Copy to temporary directory
        tmp_path = utils.temp_dir(path)

        # Create snapshot
        snapshot = parser.Snapshot(tmp_path)

        # Build release from snapshot
        # Archive the release
        utils.clear_path(release.data_dir)

        # Tar release buffer
        tar_path = os.path.join(release.data_dir, cls.archive_name)
        tar_file = tarfile.open(tar_path, 'w:gz')
        tar_file.add(tmp_path, '/')
        tar_file.close()

        # Build docker images
        snapshot.build_and_push(release, system)

        # Delete snapshot buffer
        utils.delete_path(tmp_path)

        # Build finished
        release.save()
        signals.release_created.send(sender=release)
        return release
Exemplo n.º 4
0
    def create(cls, env, group):
        """
        Creates, provisions, and saves a new host.

        :Parameters:
          - `env`: the host's environment.
          - `group`: the host's group.
        """
        domain_name = env.system.domain_name
        hostname = utils.generate_random_hex(8)
        fqdn = '%s.%s' % (hostname, domain_name) if domain_name else hostname

        host = cls(fqdn=fqdn, name=fqdn, hostname=hostname,
                   domain_name=domain_name, environment=env, group=group)

        if not env.backend:
            raise exceptions.UndefinedBackend()
        host.address = env.backend.create_host(host)
        host.finish_provisioning()
        host.save()
        log.info('Creating new instance for host...')
        host.create_instance(group.node)

        return host
Exemplo n.º 5
0
def test_generate_random_hex(choice):
    eq_(utils.generate_random_hex(2), 'aa')
    eq_(utils.generate_random_hex(4), 'aaaa')
Exemplo n.º 6
0
def test_generate_random_hex(choice):
    eq_(utils.generate_random_hex(2), 'aa')
    eq_(utils.generate_random_hex(4), 'aaaa')