@@ -22,13 +22,16 @@ import (
2222 "github.com/pivotal-cf-experimental/pcf-make-stemcell/rdiff"
2323)
2424
25+ const DefaultOSVersion = "2012R2"
26+
2527var (
2628 Version string
2729 OutputDir string
2830 OvaFile string
2931 OvfDir string
3032 VHDFile string
3133 VMDKFile string
34+ OSVersion string
3235 DeltaFile string
3336 EnableDebug bool
3437 DebugColor bool
3740var Debugf = func (format string , a ... interface {}) {}
3841
3942const UsageMessage = `
40- Usage %[1]s: [OPTIONS...] [-VMDK FILENAME] [[-VHD FILENAME] [-DELTA FILENAME]]
41- [-OUTPUT DIRNAME] [-VERSION version]
43+ Usage %[1]s: [OPTIONS...] [-VMDK FILENAME] [[-VHD FILENAME]
44+ %[2]s [-DELTA FILENAME]] [-OUTPUT DIRNAME]
45+ %[2]s [-VERSION STEMCELL_VERSION] [-OS OS_VERSION]
4246
4347Creates a BOSH stemcell from a VHD and DELTA (patch) file.
4448
@@ -77,17 +81,24 @@ Flags:
7781
7882func init () {
7983 flag .Usage = func () {
80- fmt .Fprintf (os .Stderr , UsageMessage , filepath .Base (os .Args [0 ]))
84+ exe := filepath .Base (os .Args [0 ])
85+ pad := strings .Repeat (" " , len (exe ))
86+ fmt .Fprintf (os .Stderr , UsageMessage , exe , pad )
8187 flag .PrintDefaults ()
8288 }
8389
8490 flag .StringVar (& VHDFile , "vhd" , "" , "VHD file to patch" )
8591 flag .StringVar (& VMDKFile , "vmdk" , "" , "VMDK file to create stemcell from" )
8692
87- flag .StringVar (& DeltaFile , "delta" , "" , "Patch file that will be applied to the VHD" )
93+ flag .StringVar (& DeltaFile , "delta" , "" ,
94+ "Patch file that will be applied to the VHD" )
8895 flag .StringVar (& DeltaFile , "d" , "" , "Patch file (shorthand)" )
8996
90- flag .StringVar (& Version , "version" , "" , "Stemcell version in the form of [DIGITS].[DIGITS] (e.x. 123.01)" )
97+ flag .StringVar (& OSVersion , "os" , DefaultOSVersion ,
98+ "OS version must be either 2012R2 or 2016" )
99+
100+ flag .StringVar (& Version , "version" , "" ,
101+ "Stemcell version in the form of [DIGITS].[DIGITS] (e.x. 123.01)" )
91102 flag .StringVar (& Version , "v" , "" , "Stemcell version (shorthand)" )
92103
93104 flag .StringVar (& OutputDir , "output" , "" ,
@@ -169,12 +180,20 @@ func ValidateFlags() []error {
169180 add (fmt .Errorf ("output argument (%s): is not a directory\n " , OutputDir ))
170181 }
171182
172- Debugf ("validating version string: %s" , Version )
183+ Debugf ("validating stemcell version string: %s" , Version )
173184 if err := validateVersion (Version ); err != nil {
174185 add (err )
175186 }
176187
177- name := filepath .Join (OutputDir , StemcellFilename (Version ))
188+ Debugf ("validating OS version: %s" , OSVersion )
189+ switch OSVersion {
190+ case "2012R2" , "2016" :
191+ // Ok
192+ default :
193+ add (fmt .Errorf ("OS version must be either 2012R2 or 2016 have: %s" , OSVersion ))
194+ }
195+
196+ name := filepath .Join (OutputDir , StemcellFilename (Version , OSVersion ))
178197 Debugf ("validating that stemcell filename (%s) does not exist" , name )
179198 if _ , err := os .Stat (name ); ! os .IsNotExist (err ) {
180199 add (fmt .Errorf ("file (%s) already exists - refusing to overwrite" , name ))
@@ -196,8 +215,9 @@ func validateVersion(s string) error {
196215 return nil
197216}
198217
199- func StemcellFilename (version string ) string {
200- return fmt .Sprintf ("bosh-stemcell-%s-vsphere-esxi-windows2012R2-go_agent.tgz" , version )
218+ func StemcellFilename (version , os string ) string {
219+ return fmt .Sprintf ("bosh-stemcell-%s-vsphere-esxi-windows%s-go_agent.tgz" ,
220+ version , os )
201221}
202222
203223var ErrInterupt = errors .New ("interupt" )
@@ -346,7 +366,7 @@ func (c *Config) CreateStemcell() error {
346366 return err
347367 }
348368
349- c .Stemcell = filepath .Join (tmpdir , StemcellFilename (Version ))
369+ c .Stemcell = filepath .Join (tmpdir , StemcellFilename (Version , OSVersion ))
350370 stemcell , err := os .OpenFile (c .Stemcell , os .O_CREATE | os .O_EXCL | os .O_WRONLY , 0644 )
351371 if err != nil {
352372 return err
@@ -389,10 +409,10 @@ func (c *Config) CreateStemcell() error {
389409
390410func (c * Config ) WriteManifest () error {
391411 const format = `---
392- name: bosh-vsphere-esxi-windows2012R2 -go_agent
393- version: %s
394- sha1: %s
395- operating_system: windows2012R2
412+ name: bosh-vsphere-esxi-windows%[1]s -go_agent
413+ version: %[2] s
414+ sha1: %[3] s
415+ operating_system: windows%[1]s
396416cloud_properties:
397417 infrastructure: vsphere
398418 hypervisor: esxi
@@ -416,7 +436,7 @@ cloud_properties:
416436 defer f .Close ()
417437 Debugf ("created temp stemcell.MF file: %s" , c .Manifest )
418438
419- if _ , err := fmt .Fprintf (f , format , Version , c .Sha1sum ); err != nil {
439+ if _ , err := fmt .Fprintf (f , format , OSVersion , Version , c .Sha1sum ); err != nil {
420440 os .Remove (c .Manifest )
421441 return fmt .Errorf ("writing stemcell.MF (%s): %s" , c .Manifest , err )
422442 }
@@ -554,6 +574,8 @@ func ParseFlags() error {
554574 OutputDir = wd
555575 }
556576
577+ OSVersion = strings .ToUpper (OSVersion )
578+
557579 return nil
558580}
559581
0 commit comments