github.com/coreos/mantle@v0.13.0/platform/local/configdrive.go (about)

     1  // Copyright 2015 CoreOS, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package local
    16  
    17  import (
    18  	"os"
    19  	"path"
    20  
    21  	"github.com/coreos/mantle/platform/conf"
    22  )
    23  
    24  // MakeConfigDrive creates a config drive directory tree under outputDir
    25  // and returns the path to the top level directory.
    26  func MakeConfigDrive(userdata *conf.Conf, outputDir string) (string, error) {
    27  	drivePath := path.Join(outputDir, "config-2")
    28  	userPath := path.Join(drivePath, "openstack/latest/user_data")
    29  
    30  	if err := os.MkdirAll(path.Dir(userPath), 0777); err != nil {
    31  		os.RemoveAll(drivePath)
    32  		return "", err
    33  	}
    34  
    35  	if err := userdata.WriteFile(userPath); err != nil {
    36  		os.RemoveAll(drivePath)
    37  		return "", err
    38  	}
    39  
    40  	return drivePath, nil
    41  }