func (p *parser) parseResourcePoolManifests(rawResourcePools []resourcePool, path string) ([]ResourcePool, error) { resourcePools := make([]ResourcePool, len(rawResourcePools), len(rawResourcePools)) for i, rawResourcePool := range rawResourcePools { resourcePool := ResourcePool{ Name: rawResourcePool.Name, Network: rawResourcePool.Network, Stemcell: StemcellRef(rawResourcePool.Stemcell), } cloudProperties, err := biproperty.BuildMap(rawResourcePool.CloudProperties) if err != nil { return resourcePools, bosherr.WrapErrorf(err, "Parsing resource_pool '%s' cloud_properties: %#v", rawResourcePool.Name, rawResourcePool.CloudProperties) } resourcePool.CloudProperties = cloudProperties env, err := biproperty.BuildMap(rawResourcePool.Env) if err != nil { return resourcePools, bosherr.WrapErrorf(err, "Parsing resource_pool '%s' env: %#v", rawResourcePool.Name, rawResourcePool.Env) } resourcePool.Env = env resourcePool.Stemcell.URL, err = biutil.AbsolutifyPath(path, resourcePool.Stemcell.URL, p.fs) if err != nil { return resourcePools, bosherr.WrapErrorf(err, "Resolving stemcell path '%s", resourcePool.Stemcell.URL) } resourcePools[i] = resourcePool } return resourcePools, nil }
func (p *parser) parseNetworkManifests(rawNetworks []network) ([]Network, error) { networks := make([]Network, len(rawNetworks), len(rawNetworks)) for i, rawNetwork := range rawNetworks { network := Network{ Name: rawNetwork.Name, Type: NetworkType(rawNetwork.Type), DNS: rawNetwork.DNS, } cloudProperties, err := biproperty.BuildMap(rawNetwork.CloudProperties) if err != nil { return networks, bosherr.WrapErrorf(err, "Parsing network '%s' cloud_properties: %#v", rawNetwork.Name, rawNetwork.CloudProperties) } network.CloudProperties = cloudProperties for _, subnet := range rawNetwork.Subnets { cloudProperties, err := biproperty.BuildMap(subnet.CloudProperties) if err != nil { return networks, bosherr.WrapErrorf(err, "Parsing network subnet '%s' cloud_properties: %#v", rawNetwork.Name, subnet.CloudProperties) } network.Subnets = append(network.Subnets, Subnet{ Range: subnet.Range, Gateway: subnet.Gateway, DNS: subnet.DNS, CloudProperties: cloudProperties, }) } networks[i] = network } return networks, nil }
func (p *parser) parseDeploymentManifest(depManifest manifest, path string) (Manifest, error) { deployment := boshDeploymentDefaults deployment.Name = depManifest.Name networks, err := p.parseNetworkManifests(depManifest.Networks) if err != nil { return Manifest{}, bosherr.WrapErrorf(err, "Parsing networks: %#v", depManifest.Networks) } deployment.Networks = networks resourcePools, err := p.parseResourcePoolManifests(depManifest.ResourcePools, path) if err != nil { return Manifest{}, bosherr.WrapErrorf(err, "Parsing resource_pools: %#v", depManifest.ResourcePools) } deployment.ResourcePools = resourcePools diskPools, err := p.parseDiskPoolManifests(depManifest.DiskPools) if err != nil { return Manifest{}, bosherr.WrapErrorf(err, "Parsing disk_pools: %#v", depManifest.DiskPools) } deployment.DiskPools = diskPools if len(depManifest.Jobs) > 0 && len(depManifest.InstanceGroups) > 0 { return Manifest{}, bosherr.Error("Deployment specifies both jobs and instance_groups keys, only one is allowed") } rawJobs := depManifest.Jobs if len(depManifest.InstanceGroups) > 0 { rawJobs = depManifest.InstanceGroups } jobs, err := p.parseJobManifests(rawJobs) if err != nil { return Manifest{}, bosherr.WrapErrorf(err, "Parsing jobs: %#v", depManifest.Jobs) } deployment.Jobs = jobs properties, err := biproperty.BuildMap(depManifest.Properties) if err != nil { return Manifest{}, bosherr.WrapErrorf(err, "Parsing global manifest properties: %#v", depManifest.Properties) } deployment.Properties = properties if depManifest.Update.UpdateWatchTime != nil { updateWatchTime, err := NewWatchTime(*depManifest.Update.UpdateWatchTime) if err != nil { return Manifest{}, bosherr.WrapError(err, "Parsing update watch time") } deployment.Update = Update{ UpdateWatchTime: updateWatchTime, } } return deployment, nil }
func (p *parser) Parse(path string, releaseSetManifest birelsetmanifest.Manifest) (Manifest, error) { contents, err := p.fs.ReadFile(path) if err != nil { return Manifest{}, bosherr.WrapErrorf(err, "Reading file %s", path) } comboManifest := manifest{} err = yaml.Unmarshal(contents, &comboManifest) if err != nil { return Manifest{}, bosherr.WrapError(err, "Unmarshalling installation manifest") } p.logger.Debug(p.logTag, "Parsed installation manifest: %#v", comboManifest) if comboManifest.CloudProvider.SSHTunnel.PrivateKey != "" { comboManifest.CloudProvider.SSHTunnel.PrivateKey, err = biutil.AbsolutifyPath(path, comboManifest.CloudProvider.SSHTunnel.PrivateKey, p.fs) if err != nil { return Manifest{}, bosherr.WrapErrorf(err, "Expanding private_key path") } } installationManifest := Manifest{ Name: comboManifest.Name, Template: ReleaseJobRef{ Name: comboManifest.CloudProvider.Template.Name, Release: comboManifest.CloudProvider.Template.Release, }, Mbus: comboManifest.CloudProvider.Mbus, } properties, err := biproperty.BuildMap(comboManifest.CloudProvider.Properties) if err != nil { return Manifest{}, bosherr.WrapErrorf(err, "Parsing cloud_provider manifest properties: %#v", comboManifest.CloudProvider.Properties) } installationManifest.Properties = properties if comboManifest.CloudProvider.HasSSHTunnel() { password, err := p.uuidGenerator.Generate() if err != nil { return Manifest{}, bosherr.WrapError(err, "Generating registry password") } installationManifest.PopulateRegistry("registry", password, "127.0.0.1", 6901, comboManifest.CloudProvider.SSHTunnel) } err = p.validator.Validate(installationManifest, releaseSetManifest) if err != nil { return Manifest{}, bosherr.WrapError(err, "Validating installation manifest") } return installationManifest, nil }
func (p *parser) parseDiskPoolManifests(rawDiskPools []diskPool) ([]DiskPool, error) { diskPools := make([]DiskPool, len(rawDiskPools), len(rawDiskPools)) for i, rawDiskPool := range rawDiskPools { diskPool := DiskPool{ Name: rawDiskPool.Name, DiskSize: rawDiskPool.DiskSize, } cloudProperties, err := biproperty.BuildMap(rawDiskPool.CloudProperties) if err != nil { return diskPools, bosherr.WrapErrorf(err, "Parsing disk_pool '%s' cloud_properties: %#v", rawDiskPool.Name, rawDiskPool.CloudProperties) } diskPool.CloudProperties = cloudProperties diskPools[i] = diskPool } return diskPools, nil }
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 (p *parser) parseJobManifests(rawJobs []job) ([]Job, error) { jobs := make([]Job, len(rawJobs), len(rawJobs)) for i, rawJob := range rawJobs { job := Job{ Name: rawJob.Name, Instances: rawJob.Instances, Lifecycle: JobLifecycle(rawJob.Lifecycle), PersistentDisk: rawJob.PersistentDisk, PersistentDiskPool: rawJob.PersistentDiskPool, ResourcePool: rawJob.ResourcePool, } if len(rawJob.Templates) > 0 && len(rawJob.Jobs) > 0 { return jobs, bosherr.Error("Deployment specifies both templates and jobs keys for instance_group " + job.Name + ", only one is allowed") } templates := rawJob.Templates if len(rawJob.Jobs) > 0 { templates = rawJob.Jobs } if templates != nil { releaseJobRefs := make([]ReleaseJobRef, len(templates), len(templates)) for i, rawJobRef := range templates { ref := ReleaseJobRef{ Name: rawJobRef.Name, Release: rawJobRef.Release, } if rawJobRef.Properties != nil { properties, err := biproperty.BuildMap(*rawJobRef.Properties) if err != nil { return []Job{}, bosherr.WrapErrorf(err, "Parsing release job properties: %#v", rawJobRef.Properties) } ref.Properties = &properties } releaseJobRefs[i] = ref } job.Templates = releaseJobRefs } if rawJob.Networks != nil { jobNetworks := make([]JobNetwork, len(rawJob.Networks), len(rawJob.Networks)) for i, rawJobNetwork := range rawJob.Networks { jobNetwork := JobNetwork{ Name: rawJobNetwork.Name, StaticIPs: rawJobNetwork.StaticIPs, } if rawJobNetwork.Defaults != nil { networkDefaults := make([]NetworkDefault, len(rawJobNetwork.Defaults), len(rawJobNetwork.Defaults)) for i, rawDefaults := range rawJobNetwork.Defaults { networkDefaults[i] = NetworkDefault(rawDefaults) } jobNetwork.Defaults = networkDefaults } jobNetworks[i] = jobNetwork } job.Networks = jobNetworks } if rawJob.Properties != nil { properties, err := biproperty.BuildMap(rawJob.Properties) if err != nil { return jobs, bosherr.WrapErrorf(err, "Parsing job '%s' properties: %#v", rawJob.Name, rawJob.Properties) } job.Properties = properties } jobs[i] = job } return jobs, nil }