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
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
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
def test_generate_random_hex(choice): eq_(utils.generate_random_hex(2), 'aa') eq_(utils.generate_random_hex(4), 'aaaa')