diff --git a/pkg/multicloud/zstack/host.go b/pkg/multicloud/zstack/host.go index d38015e636..b5babfd498 100644 --- a/pkg/multicloud/zstack/host.go +++ b/pkg/multicloud/zstack/host.go @@ -418,10 +418,12 @@ func (region *SRegion) CreateInstance(desc *cloudprovider.SManagedVMCreateConfig systemTags := []string{ "createWithoutCdRom::true", "usbRedirect::false", - fmt.Sprintf("staticIp::%s::%s", l3Id, desc.IpAddr), "vmConsoleMode::vnc", "cleanTraffic::false", } + if len(desc.IpAddr) > 0 { + systemTags = append(systemTags, fmt.Sprintf("staticIp::%s::%s", l3Id, desc.IpAddr)) + } if len(desc.UserData) > 0 { systemTags = append(systemTags, "userdata::"+desc.UserData) } diff --git a/pkg/multicloud/zstack/instance.go b/pkg/multicloud/zstack/instance.go index 021ff7207e..455735306e 100644 --- a/pkg/multicloud/zstack/instance.go +++ b/pkg/multicloud/zstack/instance.go @@ -31,6 +31,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/multicloud" "yunion.io/x/onecloud/pkg/util/billing" + "yunion.io/x/onecloud/pkg/util/version" ) type SInstanceCdrome struct { @@ -305,6 +306,11 @@ func (instance *SInstance) GetVNCInfo() (jsonutils.JSONObject, error) { } authURL, _ := url.Parse(instance.host.zone.region.client.authURL) url := fmt.Sprintf("%s://%s:5000/thirdparty/vnc_auto.html?host=%s&port=%d&token=%s&title=%s", info.Scheme, authURL.Hostname(), info.Hostname, info.Port, info.Token, instance.Name) + if ver, _ := instance.host.zone.region.client.GetVersion(); ver != nil { + if version.GE(ver.Version, "4.0.0") { + url = fmt.Sprintf("%s://%s:5000/novnc/index.html?host=%s&port=%d&token=%s&title=%s&language=zh-CN&lowVersion=false", info.Scheme, authURL.Hostname(), info.Hostname, info.Port, info.Token, instance.Name) + } + } password, _ := instance.host.zone.region.GetInstanceConsolePassword(instance.UUID) if len(password) > 0 { url = url + fmt.Sprintf("&password=%s", password) diff --git a/pkg/multicloud/zstack/shell/version.go b/pkg/multicloud/zstack/shell/version.go new file mode 100644 index 0000000000..1bde64f04c --- /dev/null +++ b/pkg/multicloud/zstack/shell/version.go @@ -0,0 +1,33 @@ +// 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 shell + +import ( + "yunion.io/x/onecloud/pkg/multicloud/zstack" + "yunion.io/x/onecloud/pkg/util/shellutils" +) + +func init() { + type VersionShowOptions struct { + } + shellutils.R(&VersionShowOptions{}, "version-show", "Show version", func(cli *zstack.SRegion, args *VersionShowOptions) error { + ver, err := cli.GetClient().GetVersion() + if err != nil { + return err + } + printObject(ver) + return nil + }) +} diff --git a/pkg/multicloud/zstack/version.go b/pkg/multicloud/zstack/version.go new file mode 100644 index 0000000000..7c7f738331 --- /dev/null +++ b/pkg/multicloud/zstack/version.go @@ -0,0 +1,38 @@ +// 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 zstack + +import ( + "yunion.io/x/jsonutils" + "yunion.io/x/pkg/errors" +) + +type SVersion struct { + Version string +} + +func (self *SZStackClient) GetVersion() (*SVersion, error) { + params := map[string]interface{}{ + "getVersion": map[string]string{}, + "systemTags": []string{}, + "userTags": []string{}, + } + resp, err := self.put("management-nodes/actions", "", jsonutils.Marshal(params)) + if err != nil { + return nil, errors.Wrapf(err, "GetVersion") + } + v := &SVersion{} + return v, resp.Unmarshal(v) +} diff --git a/pkg/multicloud/zstack/zstack.go b/pkg/multicloud/zstack/zstack.go index 507d3389db..1c9547e824 100644 --- a/pkg/multicloud/zstack/zstack.go +++ b/pkg/multicloud/zstack/zstack.go @@ -330,7 +330,6 @@ func (cli *SZStackClient) getResource(resource, resourceId string, retval interf } func (cli *SZStackClient) getMonitor(resource string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { - return cli._getMonitor(resource, params) }