Пример #1
0
func storageDetailsFromLegacy(legacy params.LegacyStorageDetails) params.StorageDetails {
	nowUTC := time.Now().UTC()
	details := params.StorageDetails{
		legacy.StorageTag,
		legacy.OwnerTag,
		legacy.Kind,
		params.EntityStatus{
			Status: params.Status(legacy.Status),
			Since:  &nowUTC,
		},
		legacy.Persistent,
		nil,
	}
	if legacy.UnitTag != "" {
		details.Attachments = map[string]params.StorageAttachmentDetails{
			legacy.UnitTag: params.StorageAttachmentDetails{
				legacy.StorageTag,
				legacy.UnitTag,
				"", // machine is unknown in legacy
				legacy.Location,
			},
		}
	}
	return details
}
Пример #2
0
func (api *API) createParamsStorageAttachment(si params.StorageDetails, sa state.StorageAttachment) (params.StorageDetails, error) {
	result := params.StorageDetails{Status: "pending"}
	result.StorageTag = sa.StorageInstance().String()
	if result.StorageTag != si.StorageTag {
		panic("attachment does not belong to storage instance")
	}
	result.UnitTag = sa.Unit().String()
	result.OwnerTag = si.OwnerTag
	result.Kind = si.Kind
	result.Persistent = si.Persistent
	// TODO(axw) set status according to whether storage has been provisioned.

	// This is only for provisioned attachments
	machineTag, err := api.storage.UnitAssignedMachine(sa.Unit())
	if err != nil {
		return params.StorageDetails{}, errors.Annotate(err, "getting unit for storage attachment")
	}
	info, err := common.StorageAttachmentInfo(api.storage, sa, machineTag)
	if err != nil {
		if errors.IsNotProvisioned(err) {
			// If Info returns an error, then the storage has not yet been provisioned.
			return result, nil
		}
		return params.StorageDetails{}, errors.Annotate(err, "getting storage attachment info")
	}
	result.Location = info.Location
	if result.Location != "" {
		result.Status = "attached"
	}
	return result, nil
}