Пример #1
0
func (r *reader) Read() (Release, error) {
	err := r.extractor.DecompressFileToDir(r.tarFilePath, r.extractedReleasePath, boshcmd.CompressorOptions{})
	if err != nil {
		return nil, bosherr.WrapError(err, "Extracting release")
	}

	releaseManifestPath := path.Join(r.extractedReleasePath, "release.MF")
	releaseManifestBytes, err := r.fs.ReadFile(releaseManifestPath)
	if err != nil {
		return nil, bosherr.WrapErrorf(err, "Reading release manifest '%s'", releaseManifestPath)
	}

	var manifest birelmanifest.Manifest
	err = yaml.Unmarshal(releaseManifestBytes, &manifest)
	if err != nil {
		return nil, bosherr.WrapError(err, "Parsing release manifest")
	}

	release, err := r.newReleaseFromManifest(manifest)
	if err != nil {
		return nil, bosherr.WrapError(err, "Constructing release from manifest")
	}

	return release, nil
}
Пример #2
0
func (s reader) Read(stemcellTarballPath string, extractedPath string) (ExtractedStemcell, error) {
	err := s.compressor.DecompressFileToDir(stemcellTarballPath, extractedPath, boshcmd.CompressorOptions{})
	if err != nil {
		return nil, bosherr.WrapErrorf(err, "Extracting stemcell from '%s' to '%s'", stemcellTarballPath, extractedPath)
	}

	var rawManifest manifest
	manifestPath := filepath.Join(extractedPath, "stemcell.MF")

	manifestContents, err := s.fs.ReadFile(manifestPath)
	if err != nil {
		return nil, bosherr.WrapErrorf(err, "Reading stemcell manifest '%s'", manifestPath)
	}

	err = yaml.Unmarshal(manifestContents, &rawManifest)
	if err != nil {
		return nil, bosherr.WrapErrorf(err, "Parsing stemcell manifest: %s", manifestContents)
	}

	manifest := Manifest{
		Name:    rawManifest.Name,
		Version: rawManifest.Version,
		OS:      rawManifest.OS,
		SHA1:    rawManifest.SHA1,
	}

	cloudProperties, err := biproperty.BuildMap(rawManifest.CloudProperties)
	if err != nil {
		return nil, bosherr.WrapErrorf(err, "Parsing stemcell cloud_properties: %#v", rawManifest.CloudProperties)
	}
	manifest.CloudProperties = cloudProperties

	manifest.ImagePath = filepath.Join(extractedPath, "image")

	stemcell := NewExtractedStemcell(
		manifest,
		extractedPath,
		s.fs,
	)

	return stemcell, nil
}
func (m *legacyDeploymentStateMigrator) migrate(configPath string) (deploymentState DeploymentState, err error) {
	m.logger.Info(m.logTag, "Migrating legacy bosh-deployments.yml")

	bytes, err := m.fs.ReadFile(configPath)
	if err != nil {
		return deploymentState, bosherr.WrapErrorf(err, "Reading legacy deployment state file '%s'", configPath)
	}

	// go-yaml does not currently support ':' as the first character in a key.
	regex := regexp.MustCompile("\n([- ]) :")
	parsableString := regex.ReplaceAllString(string(bytes), "\n$1 ")

	m.logger.Debug(m.logTag, "Processed legacy bosh-deployments.yml:\n%s", parsableString)

	var legacyDeploymentState legacyDeploymentState
	err = yaml.Unmarshal([]byte(parsableString), &legacyDeploymentState)
	if err != nil {
		return deploymentState, bosherr.WrapError(err, "Parsing job manifest")
	}

	m.logger.Debug(m.logTag, "Parsed legacy bosh-deployments.yml: %#v", legacyDeploymentState)

	if (len(legacyDeploymentState.Instances) > 0) && (legacyDeploymentState.Instances[0].UUID != "") {
		deploymentState.DirectorID = legacyDeploymentState.Instances[0].UUID
	} else {
		uuid, err := m.uuidGenerator.Generate()
		if err != nil {
			return deploymentState, bosherr.WrapError(err, "Generating UUID")
		}
		deploymentState.DirectorID = uuid
	}

	deploymentState.Disks = []DiskRecord{}
	deploymentState.Stemcells = []StemcellRecord{}
	deploymentState.Releases = []ReleaseRecord{}

	if len(legacyDeploymentState.Instances) > 0 {
		instance := legacyDeploymentState.Instances[0]
		diskCID := instance.DiskCID
		diskSIZE := instance.DiskSIZE
		if diskCID != "" {
			uuid, err := m.uuidGenerator.Generate()
			if err != nil {
				return deploymentState, bosherr.WrapError(err, "Generating UUID")
			}

			deploymentState.CurrentDiskID = uuid
			deploymentState.Disks = []DiskRecord{
				{
					ID:              uuid,
					CID:             diskCID,
					Size:            diskSIZE,
					CloudProperties: biproperty.Map{},
				},
			}
		}

		vmCID := instance.VMCID
		if vmCID != "" {
			deploymentState.CurrentVMCID = vmCID
		}

		agentID := instance.VMAGENTID
		if agentID != "" {
			deploymentState.CurrentAgentID = agentID
		}

		stemcellCID := instance.StemcellCID
		if stemcellCID != "" {
			uuid, err := m.uuidGenerator.Generate()
			if err != nil {
				return deploymentState, bosherr.WrapError(err, "Generating UUID")
			}

			stemcellName := instance.StemcellName
			if stemcellName == "" {
				stemcellName = "unknown-stemcell"
			}

			deploymentState.Stemcells = []StemcellRecord{
				{
					ID:      uuid,
					Name:    stemcellName,
					Version: "", // unknown, will never match new stemcell
					CID:     stemcellCID,
				},
			}
		}
	}

	m.logger.Debug(m.logTag, "New deployment.json (migrated from legacy bosh-deployments.yml): %#v", deploymentState)

	return deploymentState, nil
}