// WriteUserData generates the cloud-init user-data using the
// specified machine and network config for a container, and writes
// the serialized form out to a cloud-init file in the directory
// specified.
484481
func WriteUserData(
	instanceConfig *instancecfg.InstanceConfig,
	networkConfig *container.NetworkConfig,
	directory string,
) (string, error) {
	userData, err := CloudInitUserData(instanceConfig, networkConfig)
	if err != nil {
		logger.Errorf("failed to create user data: %v", err)
		return "", err
	}
	return WriteCloudInitFile(directory, userData)
}
1116167
func (w *asyncUdsWriter) write(data []byte) (int, error) {
	conn, err := w.ensureConnection()
	if err != nil {
		return 0, err
	}

	conn.SetWriteDeadline(time.Now().Add(w.writeTimeout))
	n, err := conn.Write(data)

	if e, isNetworkErr := err.(net.Error); !isNetworkErr || !e.Temporary() {
		// err is not temporary, Statsd server disconnected, retry connecting at next packet
		w.unsetConnection()
		return 0, e
	}

	return n, err
}
728914
func (ini *INI) WriteTo(w io.Writer) (int64, error) {
	var written int64

	// Global section.
	m, err := ini.printSection(w, &ini.global)
	written += int64(m)
	if err != nil {
		return written, err
	}
	first := len(ini.global.Data) > 0

	for i, section := range ini.sections {
		if i > 0 || first {
			m, err := fmt.Fprintf(w, "\n")
			written += int64(m)
			if err != nil {
				return written, err
			}
		}
		m, err := ini.printSection(w, section)
		written += int64(m)
		if err != nil {
			return written, err
		}
	}

	return written, nil
}
139775
func (f *JSONConfigFile) GetUserConfigForUID(u keybase1.UID) (*UserConfig, error) {

	if uc := f.copyUserConfigIfForUID(u); uc != nil {
		return uc, nil
	}

	d := f.jw.AtKey("users")
	keys, _ := d.Keys()
	for _, key := range keys {
		uc, err := f.GetUserConfigForUsername(NewNormalizedUsername(key))
		if err == nil && uc != nil && uc.GetUID().Equal(u) {
			return uc, nil
		}
	}
	return nil, nil
}
722639
func (wb *WriteBatch) BatchData() *BatchData {
	data := wb.wb.Data()
	if wb.data == nil {
		wb.data = new(BatchData)
	}

	wb.data.Load(data)
	return wb.data
}
1181704
func WritePersonalCloudMetadata(cloudsMap map[string]Cloud) error {
	data, err := marshalCloudMetadata(cloudsMap)
	if err != nil {
		return errors.Trace(err)
	}
	return ioutil.WriteFile(JujuPersonalCloudsPath(), data, os.FileMode(0600))
}
317895
func (c *accessCloudCommand) Init(args []string) error {
	if len(args) < 1 {
		return errors.New("no user specified")
	}

	if len(args) < 2 {
		return errors.New("no permission level specified")
	}

	c.User = args[0]
	c.Access = args[1]
	// The remaining args are cloud names.
	for _, arg := range args[2:] {
		if !names.IsValidCloud(arg) {
			return errors.NotValidf("cloud name %q", arg)
		}
		c.Clouds = append(c.Clouds, arg)
	}

	// Special case for backwards compatibility.
	if c.Access == "addmodel" {
		c.Access = "add-model"
	}
	if len(c.Clouds) > 0 {
		return permission.ValidateCloudAccess(permission.Access(c.Access))
	}
	return errors.Errorf("You need to specify one or more cloud names.\n" +
		"See 'juju help grant-cloud'.")
}
530611
func (s *GlobConfig) Write() error {
	key := globalConfigPath
	return s.StateDriver.WriteState(key, s, json.Marshal)
}
197602
func (c *Context) Write(data interface{}) error {
	return c.writer.Write(c.Response, data)
}
754960
func (s *stepCreateInstance) generateUserData(userData string, httpGETOnly bool) (string, error) {
	renderedUserData, err := interpolate.Render(userData, &s.Ctx)
	if err != nil {
		return "", fmt.Errorf("Error rendering user_data: %s", err)
	}

	ud := base64.StdEncoding.EncodeToString([]byte(renderedUserData))

	// DeployVirtualMachine uses POST by default which allows 32K of
	// userdata. If using GET instead the userdata is limited to 2K.
	maxUD := 32768
	if httpGETOnly {
		maxUD = 2048
	}

	if len(ud) > maxUD {
		return "", fmt.Errorf(
			"The supplied user_data contains %d bytes after encoding, "+
				"this exceeds the limit of %d bytes", len(ud), maxUD)
	}

	return ud, nil
}
1150973
func CheckUserData(l *State, index int, name string) interface{} {
	if d := TestUserData(l, index, name); d != nil {
		return d
	}
	typeError(l, index, name)
	panic("unreachable")
}
709232
func (p *Prefix) writeTo(buffer *bytes.Buffer) {
	buffer.WriteString(p.Name)
	if len(p.User) > 0 {
		buffer.WriteByte(prefixUser)
		buffer.WriteString(p.User)
	}
	if len(p.Host) > 0 {
		buffer.WriteByte(prefixHost)
		buffer.WriteString(p.Host)
	}
	return
}
1363929
func (b *IOPinDriver) WritePinData(pin string, data byte) (err error) {
	i, err := strconv.Atoi(pin)
	if err != nil {
		return
	}

	buf := []byte{byte(i), data}
	err = b.adaptor().WriteCharacteristic(pinDataCharacteristic, buf)
	return err
}
847477
func (_class UserClass) Create(sessionID SessionRef, args UserRecord) (_retval UserRef, _err error) {
	_method := "user.create"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_argsArg, _err := convertUserRecordToXen(fmt.Sprintf("%s(%s)", _method, "args"), args)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _argsArg)
	if _err != nil {
		return
	}
	_retval, _err = convertUserRefToGo(_method + " -> ", _result.Value)
	return
}
283250
func WriteData(w http.ResponseWriter, code int, v []byte) error {
	w.Header().Set("Content-Type", "application/octet-stream")
	w.WriteHeader(code)
	if _, err := w.Write(v); err != nil {
		return err
	}
	return nil
}
1018648
func (l *State) ToUserData(index int) interface{} {
	if d, ok := l.indexToValue(index).(*userData); ok {
		return d.data
	}
	return nil
}
598620
func writeFile(path string, data []byte, mode os.FileMode) error {
	// Ensure that the parent directory is user-writable, since this is a
	// requirement in order to make modifications to that directory.
	parentDir := filepath.Dir(path)
	if err := filesystem.MakePathUserWritable(parentDir, nil); err != nil {
		return errors.Annotate(err, "failed to mark parent directory user-writable").
			InternalReason("path(%q)", parentDir).Err()
	}

	// Ensure that the target path doesn't already exist. Use filesystem.RemoveAll
	// in case it exists, but is not user-writable.
	if err := filesystem.RemoveAll(path); err != nil {
		return err
	}
	if err := ioutil.WriteFile(path, data, mode); err != nil {
		return errors.Annotate(err, "could not write file contents").InternalReason("path(%q)", path).Err()
	}
	return nil
}