moc-sdk-for-go/services/storage/container/container.go

79 строки
2.2 KiB
Go
Исходник Обычный вид История

2020-07-14 03:02:41 +03:00
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache v2.0 License.
package container
import (
2021-05-26 21:44:34 +03:00
"code.cloudfoundry.org/bytefmt"
2020-07-14 03:02:41 +03:00
"github.com/microsoft/moc-sdk-for-go/services/storage"
2020-09-08 23:04:05 +03:00
"github.com/microsoft/moc/pkg/errors"
"github.com/microsoft/moc/pkg/status"
"github.com/microsoft/moc/pkg/tags"
2020-09-08 23:04:05 +03:00
wssdcloudstorage "github.com/microsoft/moc/rpc/cloudagent/storage"
2020-07-14 03:02:41 +03:00
)
// Conversion functions from storage to wssdcloudstorage
func getWssdContainer(c *storage.Container, locationName string) (*wssdcloudstorage.Container, error) {
if c.Name == nil {
2021-05-26 21:44:34 +03:00
return nil, errors.Wrapf(errors.InvalidInput, "Storage Container name is missing")
2020-07-14 03:02:41 +03:00
}
if len(locationName) == 0 {
return nil, errors.Wrapf(errors.InvalidInput, "Location not specified")
}
wssdcontainer := &wssdcloudstorage.Container{
Name: *c.Name,
LocationName: locationName,
Tags: tags.MapToProto(c.Tags),
2020-07-14 03:02:41 +03:00
}
if c.Version != nil {
if wssdcontainer.Status == nil {
wssdcontainer.Status = status.InitStatus()
}
wssdcontainer.Status.Version.Number = *c.Version
}
if c.ContainerProperties != nil {
if c.Path != nil {
wssdcontainer.Path = *c.Path
}
2023-09-20 04:05:07 +03:00
wssdcontainer.Isolated = c.Isolated
2020-07-14 03:02:41 +03:00
}
return wssdcontainer, nil
}
func getVirtualharddisktype(enum string) wssdcloudstorage.ContainerType {
typevalue := wssdcloudstorage.ContainerType(0)
typevTmp, ok := wssdcloudstorage.ContainerType_value[enum]
if ok {
typevalue = wssdcloudstorage.ContainerType(typevTmp)
}
return typevalue
}
// Conversion function from wssdcloudstorage to storage
func getContainer(c *wssdcloudstorage.Container, location string) *storage.Container {
2021-06-14 11:54:31 +03:00
var totalSize string
var availSize string
if c.Info != nil {
totalSize = bytefmt.ByteSize(c.Info.Capacity.TotalBytes)
availSize = bytefmt.ByteSize(c.Info.Capacity.AvailableBytes)
}
2020-07-14 03:02:41 +03:00
return &storage.Container{
Name: &c.Name,
ID: &c.Id,
ContainerProperties: &storage.ContainerProperties{
Statuses: status.GetStatuses(c.GetStatus()),
Path: &c.Path,
2023-09-20 04:05:07 +03:00
Isolated: c.Isolated,
2021-05-26 21:44:34 +03:00
ContainerInfo: &storage.ContainerInfo{
AvailableSize: availSize,
TotalSize: totalSize,
},
2020-07-14 03:02:41 +03:00
},
Version: &c.Status.Version.Number,
Tags: tags.ProtoToMap(c.Tags),
2020-07-14 03:02:41 +03:00
}
}