feat(region): support oracle cloud (#18676)

This commit is contained in:
屈轩
2023-11-14 19:43:23 +08:00
committed by GitHub
parent f38441c251
commit 7cf461e8b7
36 changed files with 4636 additions and 14 deletions
+5
View File
@@ -70,6 +70,7 @@ const (
CLOUD_PROVIDER_BAIDU = compute.CLOUD_PROVIDER_BAIDU
CLOUD_PROVIDER_CUCLOUD = compute.CLOUD_PROVIDER_CUCLOUD
CLOUD_PROVIDER_QINGCLOUD = compute.CLOUD_PROVIDER_QINGCLOUD
CLOUD_PROVIDER_ORACLE = compute.CLOUD_PROVIDER_ORACLE
CLOUD_PROVIDER_GENERICS3 = compute.CLOUD_PROVIDER_GENERICS3
CLOUD_PROVIDER_CEPH = compute.CLOUD_PROVIDER_CEPH
@@ -152,6 +153,7 @@ var (
CLOUD_PROVIDER_BAIDU,
CLOUD_PROVIDER_CUCLOUD,
CLOUD_PROVIDER_QINGCLOUD,
CLOUD_PROVIDER_ORACLE,
}
CLOUD_PROVIDER_HOST_TYPE_MAP = map[string][]string{
@@ -247,6 +249,9 @@ var (
CLOUD_PROVIDER_QINGCLOUD: {
HOST_TYPE_QINGCLOUD,
},
CLOUD_PROVIDER_ORACLE: {
HOST_TYPE_ORACLE,
},
}
)
+5
View File
@@ -215,6 +215,7 @@ const (
HYPERVISOR_BAIDU = compute.HYPERVISOR_BAIDU
HYPERVISOR_CUCLOUD = compute.HYPERVISOR_CUCLOUD
HYPERVISOR_QINGCLOUD = compute.HYPERVISOR_QINGCLOUD
HYPERVISOR_ORACLE = compute.HYPERVISOR_ORACLE
// HYPERVISOR_DEFAULT = HYPERVISOR_KVM
HYPERVISOR_DEFAULT = HYPERVISOR_KVM
@@ -293,6 +294,7 @@ var HYPERVISORS = []string{
HYPERVISOR_BAIDU,
HYPERVISOR_CUCLOUD,
HYPERVISOR_QINGCLOUD,
HYPERVISOR_ORACLE,
}
var ONECLOUD_HYPERVISORS = []string{
@@ -317,6 +319,7 @@ var PUBLIC_CLOUD_HYPERVISORS = []string{
HYPERVISOR_BAIDU,
HYPERVISOR_CUCLOUD,
HYPERVISOR_QINGCLOUD,
HYPERVISOR_ORACLE,
}
var PRIVATE_CLOUD_HYPERVISORS = []string{
@@ -370,6 +373,7 @@ var HYPERVISOR_HOSTTYPE = map[string]string{
HYPERVISOR_BAIDU: HOST_TYPE_BAIDU,
HYPERVISOR_CUCLOUD: HOST_TYPE_CUCLOUD,
HYPERVISOR_QINGCLOUD: HOST_TYPE_QINGCLOUD,
HYPERVISOR_ORACLE: HOST_TYPE_ORACLE,
}
var HOSTTYPE_HYPERVISOR = map[string]string{
@@ -405,6 +409,7 @@ var HOSTTYPE_HYPERVISOR = map[string]string{
HOST_TYPE_BAIDU: HYPERVISOR_BAIDU,
HOST_TYPE_CUCLOUD: HYPERVISOR_CUCLOUD,
HOST_TYPE_QINGCLOUD: HYPERVISOR_QINGCLOUD,
HOST_TYPE_ORACLE: HYPERVISOR_ORACLE,
}
const (
+2
View File
@@ -55,6 +55,7 @@ const (
HOST_TYPE_BAIDU = compute.HOST_TYPE_BAIDU
HOST_TYPE_CUCLOUD = compute.HOST_TYPE_CUCLOUD
HOST_TYPE_QINGCLOUD = compute.HOST_TYPE_QINGCLOUD
HOST_TYPE_ORACLE = compute.HOST_TYPE_ORACLE
HOST_TYPE_DEFAULT = HOST_TYPE_HYPERVISOR
@@ -150,6 +151,7 @@ var HOST_TYPES = []string{
HOST_TYPE_BAIDU,
HOST_TYPE_CUCLOUD,
HOST_TYPE_QINGCLOUD,
HOST_TYPE_ORACLE,
}
var ALL_NIC_TYPES = []compute.TNicType{NIC_TYPE_IPMI, NIC_TYPE_ADMIN, NIC_TYPE_NORMAL}
+104
View File
@@ -0,0 +1,104 @@
// 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 guestdrivers
import (
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/pkg/util/billing"
"yunion.io/x/pkg/util/rbacscope"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/mcclient"
)
type SOracleGuestDriver struct {
SManagedVirtualizedGuestDriver
}
func init() {
driver := SOracleGuestDriver{}
models.RegisterGuestDriver(&driver)
}
func (self *SOracleGuestDriver) DoScheduleSKUFilter() bool { return false }
func (self *SOracleGuestDriver) GetHypervisor() string {
return api.HYPERVISOR_ORACLE
}
func (self *SOracleGuestDriver) GetProvider() string {
return api.CLOUD_PROVIDER_ORACLE
}
func (self *SOracleGuestDriver) GetDefaultSysDiskBackend() string {
return ""
}
func (self *SOracleGuestDriver) GetMinimalSysDiskSizeGb() int {
return 20
}
func (self *SOracleGuestDriver) GetComputeQuotaKeys(scope rbacscope.TRbacScope, ownerId mcclient.IIdentityProvider, brand string) models.SComputeResourceKeys {
keys := models.SComputeResourceKeys{}
keys.SBaseProjectQuotaKeys = quotas.OwnerIdProjectQuotaKeys(scope, ownerId)
keys.CloudEnv = api.CLOUD_ENV_PUBLIC_CLOUD
keys.Provider = api.CLOUD_PROVIDER_ORACLE
keys.Brand = api.CLOUD_PROVIDER_ORACLE
keys.Hypervisor = api.HYPERVISOR_ORACLE
return keys
}
func (self *SOracleGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapability {
return cloudprovider.SInstanceCapability{
Hypervisor: self.GetHypervisor(),
Provider: self.GetProvider(),
DefaultAccount: cloudprovider.SDefaultAccount{
Linux: cloudprovider.SOsDefaultAccount{
DefaultAccount: api.VM_DEFAULT_LINUX_LOGIN_USER,
Changeable: false,
},
Windows: cloudprovider.SOsDefaultAccount{
DefaultAccount: api.VM_DEFAULT_WINDOWS_LOGIN_USER,
Changeable: false,
},
},
}
}
func (self *SOracleGuestDriver) GetGuestInitialStateAfterCreate() string {
return api.VM_READY
}
func (self *SOracleGuestDriver) GetGuestInitialStateAfterRebuild() string {
return api.VM_READY
}
func (self *SOracleGuestDriver) AllowReconfigGuest() bool {
return true
}
func (self *SOracleGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle) bool {
return false
}
func (self *SOracleGuestDriver) IsSupportPublicipToEip() bool {
return false
}
func (self *SOracleGuestDriver) IsSupportSetAutoRenew() bool {
return false
}
+37
View File
@@ -0,0 +1,37 @@
// 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 hostdrivers
import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/compute/models"
)
type SOracleHostDriver struct {
SManagedVirtualizationHostDriver
}
func init() {
driver := SOracleHostDriver{}
models.RegisterHostDriver(&driver)
}
func (self *SOracleHostDriver) GetHostType() string {
return api.HOST_TYPE_ORACLE
}
func (self *SOracleHostDriver) GetHypervisor() string {
return api.HYPERVISOR_ORACLE
}
+2 -2
View File
@@ -88,10 +88,10 @@ type SCloudaccount struct {
ProjectId string `name:"tenant_id" width:"128" charset:"ascii" list:"user" create:"domain_optional"`
// 云环境连接地址
AccessUrl string `width:"64" charset:"ascii" nullable:"true" list:"domain" update:"domain" create:"domain_optional"`
AccessUrl string `width:"128" charset:"ascii" nullable:"true" list:"domain" update:"domain" create:"domain_optional"`
// 云账号
Account string `width:"128" charset:"ascii" nullable:"false" list:"domain" create:"domain_required"`
Account string `width:"256" charset:"ascii" nullable:"false" list:"domain" create:"domain_required"`
// 云账号密码
Secret string `length:"0" charset:"ascii" nullable:"false" list:"domain" create:"domain_required"`
+2 -2
View File
@@ -98,9 +98,9 @@ type SCloudprovider struct {
// Version string `width:"32" charset:"ascii" nullable:"true" list:"domain"` // Column(VARCHAR(32, charset='ascii'), nullable=True)
// Sysinfo jsonutils.JSONObject `get:"domain"` // Column(JSONEncodedDict, nullable=True)
AccessUrl string `width:"64" charset:"ascii" nullable:"true" list:"domain" update:"domain" create:"domain_optional"`
AccessUrl string `width:"128" charset:"ascii" nullable:"true" list:"domain" update:"domain" create:"domain_optional"`
// 云账号的用户信息,例如用户名,access key等
Account string `width:"128" charset:"ascii" nullable:"false" list:"domain" create:"domain_required"`
Account string `width:"256" charset:"ascii" nullable:"false" list:"domain" create:"domain_required"`
// 云账号的密码信息,例如密码,access key secret等。该字段在数据库加密存储。Google需要存储秘钥证书,需要此字段比较长
Secret string `length:"0" charset:"ascii" nullable:"false" list:"domain" create:"domain_required"`
+40
View File
@@ -0,0 +1,40 @@
// 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 regiondrivers
import (
"context"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/mcclient"
)
type SOracleRegionDriver struct {
SManagedVirtualizationRegionDriver
}
func init() {
driver := SOracleRegionDriver{}
models.RegisterRegionDriver(&driver)
}
func (self *SOracleRegionDriver) GetProvider() string {
return api.CLOUD_PROVIDER_ORACLE
}
func (self *SOracleRegionDriver) ValidateCreateSnapshotData(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, storage *models.SStorage, input *api.SnapshotCreateInput) error {
return nil
}
+18
View File
@@ -1419,3 +1419,21 @@ type SQingCloudCloudAccountUpdateCredentialOptions struct {
func (opts *SQingCloudCloudAccountUpdateCredentialOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(opts), nil
}
type SOracleCloudAccountCreateOptions struct {
SCloudAccountCreateBaseOptions
OraclePrivateKeyFile string `help:"Oracle private key" positional:"true"`
OracleTenancyOCID string
OracleUserOCID string
}
func (opts *SOracleCloudAccountCreateOptions) Params() (jsonutils.JSONObject, error) {
params := jsonutils.Marshal(opts).(*jsonutils.JSONDict)
params.Add(jsonutils.NewString("OracleCloud"), "provider")
data, err := ioutil.ReadFile(opts.OraclePrivateKeyFile)
if err != nil {
return nil, err
}
params.Set("oracle_private_key", jsonutils.NewString(string(data)))
return params, nil
}