fix(region): enable zstack allocate ip by itself

This commit is contained in:
Qu Xuan
2021-08-24 16:07:53 +08:00
parent 338a921368
commit f1d422e85f
5 changed files with 80 additions and 2 deletions
+3 -1
View File
@@ -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)
}
+6
View File
@@ -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)
+33
View File
@@ -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
})
}
+38
View File
@@ -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)
}
-1
View File
@@ -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)
}