mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #155 in YUNIONIO/onecloud from release/2.1.0 to release/2.2.0
* commit '283077f9599cd7d13da316516f1a1a3b9156e4d0': storage-list显示详情信息 增加network-set-static-routes等命令
This commit is contained in:
@@ -474,4 +474,38 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type HostCreateOptions struct {
|
||||
ZONE string `help:"Zone where the host is located"`
|
||||
NAME string `help:"Name of baremetal"`
|
||||
MAC string `help:"Default MAC address of baremetal"`
|
||||
Rack string `help:"Rack number of baremetal"`
|
||||
Slots string `help:"Slots number of baremetal"`
|
||||
IpmiPasswd string `help:"IPMI user password"`
|
||||
IpmiAddr string `help:"IPMI IP address"`
|
||||
}
|
||||
R(&HostCreateOptions{}, "host-create", "Create a baremetal host", func(s *mcclient.ClientSession, args *HostCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
params.Add(jsonutils.NewString(args.MAC), "access_mac")
|
||||
params.Add(jsonutils.NewString("baremetal"), "host_type")
|
||||
if len(args.Rack) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Rack), "rack")
|
||||
}
|
||||
if len(args.Slots) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Slots), "slots")
|
||||
}
|
||||
if len(args.IpmiPasswd) > 0 {
|
||||
params.Add(jsonutils.NewString(args.IpmiPasswd), "ipmi_password")
|
||||
}
|
||||
if len(args.IpmiAddr) > 0 {
|
||||
params.Add(jsonutils.NewString(args.IpmiAddr), "ipmi_ip_addr")
|
||||
}
|
||||
result, err := modules.Hosts.CreateInContext(s, params, &modules.Zones, args.ZONE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -142,6 +142,15 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&NetworkShowOptions{}, "network-metadata", "Show metadata of a network", func(s *mcclient.ClientSession, args *NetworkShowOptions) error {
|
||||
result, err := modules.Networks.GetMetadata(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&NetworkShowOptions{}, "network-private", "Make a network private", func(s *mcclient.ClientSession, args *NetworkShowOptions) error {
|
||||
result, err := modules.Networks.PerformAction(s, args.ID, "private", nil)
|
||||
if err != nil {
|
||||
@@ -288,4 +297,102 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type NetworkStaticRoutesOptions struct {
|
||||
NETWORK string `help:"ID or name of the network"`
|
||||
Net []string `help:"destination network of static route"`
|
||||
Gw []string `help:"gateway address for the static route"`
|
||||
}
|
||||
R(&NetworkStaticRoutesOptions{}, "network-set-static-routes", "Set static routes for a network", func(s *mcclient.ClientSession, args *NetworkStaticRoutesOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.Net) > 0 && len(args.Gw) > 0 {
|
||||
if len(args.Net) != len(args.Gw) {
|
||||
return fmt.Errorf("Inconsistent network and gateway pairs")
|
||||
}
|
||||
routes := jsonutils.NewDict()
|
||||
for i := 0; i < len(args.Net); i += 1 {
|
||||
routes.Add(jsonutils.NewString(args.Gw[i]), args.Net[i])
|
||||
}
|
||||
params.Add(routes, "static_routes")
|
||||
} else {
|
||||
params.Add(jsonutils.JSONNull, "static_routes")
|
||||
}
|
||||
result, err := modules.Networks.PerformAction(s, args.NETWORK, "metadata", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type NetworkAddDnsUpdateTargetOptions struct {
|
||||
ID string `help:"Network ID or name"`
|
||||
DNS string `help:"DNS server address" metavar:"DNS_SERVER"`
|
||||
KEY string `help:"DNS update key name" metavar:"DNS_UPDATE_KEY"`
|
||||
SECRET string `help:"DNS update key secret" metavar:"DNS_UPDATE_SECRET"`
|
||||
}
|
||||
R(&NetworkAddDnsUpdateTargetOptions{}, "network-add-dns-update-target", "Add a dns update target to a network", func(s *mcclient.ClientSession, args *NetworkAddDnsUpdateTargetOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.DNS), "server")
|
||||
params.Add(jsonutils.NewString(args.KEY), "key")
|
||||
params.Add(jsonutils.NewString(args.SECRET), "secret")
|
||||
result, err := modules.Networks.PerformAction(s, args.ID, "add-dns-update-target", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type NetworkRemoveDnsUpdateTargetOptions struct {
|
||||
ID string `help:"Network ID or name"`
|
||||
DNS string `help:"DNS server address" metavar:"DNS_SERVER"`
|
||||
KEY string `help:"DNS update key name" metavar:"DNS_UPDATE_KEY"`
|
||||
}
|
||||
R(&NetworkRemoveDnsUpdateTargetOptions{}, "network-remove-dns-update-target", "Remove a dns update target from a network", func(s *mcclient.ClientSession, args *NetworkRemoveDnsUpdateTargetOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.DNS), "server")
|
||||
params.Add(jsonutils.NewString(args.KEY), "key")
|
||||
result, err := modules.Networks.PerformAction(s, args.ID, "remove-dns-update-target", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type NetworkSetDnsUpdateKeyOptions struct {
|
||||
ID string `help:"ID of virtual network to update"`
|
||||
KEY string `help:"Key name of secret" metavar:"KEYNAME"`
|
||||
SECRET string `help:"Key secret"`
|
||||
SERVER string `help:"Alternate DNS update server"`
|
||||
}
|
||||
R(&NetworkSetDnsUpdateKeyOptions{}, "network-set-dns-update-key", "Set DNS update key info for a virtual network", func(s *mcclient.ClientSession, args *NetworkSetDnsUpdateKeyOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.KEY), "dns_update_key_name")
|
||||
params.Add(jsonutils.NewString(args.SECRET), "dns_update_key_secret")
|
||||
params.Add(jsonutils.NewString(args.SERVER), "dns_update_server")
|
||||
result, err := modules.Networks.PerformAction(s, args.ID, "metadata", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type NetworkRemoveDnsUpdateKeyOptions struct {
|
||||
ID string `help:"ID of virtual network"`
|
||||
}
|
||||
R(&NetworkRemoveDnsUpdateKeyOptions{}, "network-remove-dns-update-key", "Set DNS update key info for a virtual network", func(s *mcclient.ClientSession, args *NetworkRemoveDnsUpdateKeyOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.JSONNull, "dns_update_key_name")
|
||||
params.Add(jsonutils.JSONNull, "dns_update_key_secret")
|
||||
params.Add(jsonutils.JSONNull, "dns_update_server")
|
||||
result, err := modules.Networks.PerformAction(s, args.ID, "metadata", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -105,6 +105,30 @@ func (manager *SStorageManager) AllowListItems(ctx context.Context, userCred mcc
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SStorage) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict {
|
||||
used := self.GetUsedCapacity(tristate.True)
|
||||
waste := self.GetUsedCapacity(tristate.False)
|
||||
vcapa := float32(self.GetCapacity()) * self.GetOvercommitBound()
|
||||
extra.Add(jsonutils.NewInt(int64(used)), "used_capacity")
|
||||
extra.Add(jsonutils.NewInt(int64(waste)), "waste_capacity")
|
||||
extra.Add(jsonutils.NewFloat(float64(vcapa)), "virtual_capacity")
|
||||
extra.Add(jsonutils.NewFloat(float64(vcapa-float32(used)-float32(waste))), "free_capacity")
|
||||
if self.GetCapacity() > 0 {
|
||||
value := float64(used * 1.0 / self.GetCapacity())
|
||||
value = float64(int(value*100+0.5) / 100.0)
|
||||
extra.Add(jsonutils.NewFloat(value), "commit_rate")
|
||||
} else {
|
||||
extra.Add(jsonutils.NewFloat(0.0), "commit_rate")
|
||||
}
|
||||
extra.Add(jsonutils.NewFloat(float64(self.GetOvercommitBound())), "commit_bound")
|
||||
return extra
|
||||
}
|
||||
|
||||
func (self *SStorage) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
extra := self.SEnabledStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
return self.getMoreDetails(extra)
|
||||
}
|
||||
|
||||
func (self *SStorage) GetUsedCapacity(isReady tristate.TriState) int {
|
||||
disks := DiskManager.Query().SubQuery()
|
||||
q := disks.Query(sqlchemy.SUM("sum", disks.Field("disk_size"))).Equals("storage_id", self.Id)
|
||||
|
||||
Reference in New Issue
Block a user