| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- // Copyright 2019 Yunion
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package options
- import (
- "time"
- "yunion.io/x/jsonutils"
- )
- type WebConsoleOptions struct {
- WebconsoleUrl string `help:"Frontend webconsole url" short-token:"w" default:"$WEBCONSOLE_URL"`
- }
- type PodBaseOptions struct {
- WebConsoleOptions
- NAME string `help:"Name of k8s pod to connect"`
- Namespace string `help:"Namespace of this pod"`
- Container string `help:"Container in this pod"`
- Cluster string `default:"$K8S_CLUSTER|default" help:"Kubernetes cluster name"`
- }
- func (opt *PodBaseOptions) Params() (*jsonutils.JSONDict, error) {
- return StructToParams(opt)
- }
- type PodShellOptions struct {
- PodBaseOptions
- }
- type PodLogOptoins struct {
- PodBaseOptions
- Since string `help:"Only return logs newer than a relative duration like 5s, 2m or 3h"`
- }
- func (opt *PodLogOptoins) Params() (*jsonutils.JSONDict, error) {
- params, err := opt.PodBaseOptions.Params()
- if err != nil {
- return nil, err
- }
- if opt.Since != "" {
- _, err = time.ParseDuration(opt.Since)
- if err != nil {
- return nil, err
- }
- params.Add(jsonutils.NewString(opt.Since), "since")
- }
- return params, nil
- }
- type WebConsoleBaremetalOptions struct {
- WebConsoleOptions
- ID string `help:"Baremetal host id or name"`
- }
- func (opt *WebConsoleBaremetalOptions) Params() (*jsonutils.JSONDict, error) {
- return StructToParams(opt)
- }
- type WebConsoleSshOptions struct {
- WebConsoleOptions
- ID string `help:"ID of server" json:"-"`
- Ip string `help:"IP to connect if multiple IPs on server"`
- Port int `help:"Remote server port"`
- Username string `help:"Remote server username"`
- KeepUsername bool `help:"Keep remove username"`
- Password string `help:"Remote server password"`
- ResourceType string `help:"Resource Type" choices:"host|server"`
- }
- func (opt *WebConsoleSshOptions) Params() (*jsonutils.JSONDict, error) {
- data, err := StructToParams(opt)
- if err != nil {
- return nil, err
- }
- params := jsonutils.NewDict()
- params.Set("webconsole", data)
- return params, nil
- }
- type WebConsoleServerOptions struct {
- WebConsoleOptions
- ID string `help:"Server id or name"`
- }
- type WebConsoleServerRdpOptions struct {
- WebConsoleOptions
- ID string `help:"Server id or name"`
- Host *string
- Port *int
- Username *string
- Password *string
- Width *int
- Height *int
- Dpi *int
- }
- type WebConsoleContainerExecOptions struct {
- WebConsoleOptions
- ID string `help:"Container id or name"`
- }
|