Skip to content

Commit

Permalink
fix(region): huawei subaccount
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito committed Dec 21, 2023
1 parent 5a02dfc commit f721ef7
Show file tree
Hide file tree
Showing 21 changed files with 365 additions and 390 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,5 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.0.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace yunion.io/x/cloudmux => /Users/quxuan/.go/src/yunion.io/x/cloudmux
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1201,8 +1201,6 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231220111515-f4d6c15e4077 h1:uzfyl/PcxvNAYHwf+uOXnNRxucRIoLC3xLbdLhp68o0=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231220111515-f4d6c15e4077/go.mod h1:aj1gR9PPb6eqqKOwvANe26CoZFY8ydmXy0fuvgKYXH0=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
Expand Down
132 changes: 132 additions & 0 deletions scripts/upgrade_3_11.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/env bash

HOST='127.0.0.1'
USERNAME='root'
PASSWORD=''
DATETIME=$(date -v-10d -u "+%Y-%m-%dT%H:%M%SZ")
echo $DATETIME

function exec_sql_with_db() {
export MYSQL_PWD=$PASSWORD
local db=$1
local sql=$2
echo $(mysql -u"$USERNAME" -h "$HOST" -D"$db" -s -e "$sql")
}

function get_relation_tables() {
local field=$1
exec_sql_with_db "information_schema" "select table_name from columns where column_name='$field' and table_schema='yunioncloud'"
}

function exec_sql() {
exec_sql_with_db "yunioncloud" "$1"
}

function uuid() {
echo $1 | awk -F '-' '{print $1"-"$2"-"$3"-"$4"-"$5}'
}

function change_uuid() {
local table=$1
local target_id=$2

uid=$(uuid $target_id)
if [ "$uid" != "$target_id" ]; then
target_id=$uid
else
exec_sql "update $table set id='$target_id-old' where id='$target_id'"
fi
echo $target_id
}


echo "upgrade guests_tbl"
exec_sql "select name, id, external_id from guests_tbl where deleted=1 and length(external_id) > 0 and host_id in (select id from hosts_tbl where deleted=1 and manager_id in (select id from cloudproviders_tbl where deleted=1 and provider='Huawei' and deleted_at > '$DATETIME'))" | while read -r line; do
info=($(echo $line | tr " ", "\n"))
name=${info[0]}
target_id=${info[1]}
external_id=${info[2]}
id=$(exec_sql "select id from guests_tbl where deleted=0 and external_id='$external_id' and host_id in (select id from hosts_tbl where deleted=0 and manager_id in (select id from cloudproviders_tbl where deleted=0 and provider='Huawei'))")
if [ -n "$id" ]; then
target_id=$(change_uuid "guests_tbl" $target_id)
echo "change server $name id from $id => $target_id"

exec_sql "update guests_tbl set id='$target_id' where id='$id' and deleted=0"

tables=$(get_relation_tables "guest_id")
for table in $tables; do
exec_sql "update $table set guest_id='$target_id' where guest_id='$id' and deleted=0"
done

fi

done

echo "upgrade networks_tbl"
exec_sql "select name, id, external_id from networks_tbl where deleted=1 and length(external_id) > 0 and wire_id in (select id from wires_tbl where deleted=1 and vpc_id in (select id from vpcs_tbl where deleted=1 and manager_id in (select id from cloudproviders_tbl where deleted=1 and provider='Huawei' and deleted_at > '$DATETIME')))" | while read -r line; do
info=($(echo $line | tr " ", "\n"))
name=${info[0]}
target_id=${info[1]}
external_id=${info[2]}
id=$(exec_sql "select id from networks_tbl where deleted=0 and external_id='$external_id' and wire_id in (select id from wires_tbl where deleted=0 and vpc_id in (select id from vpcs_tbl where deleted=0 and manager_id in (select id from cloudproviders_tbl where deleted=0 and provider='Huawei')))")
if [ -n "$id" ]; then
target_id=$(change_uuid "networks_tbl" $target_id)
echo "change network $name id from $id => $target_id"

exec_sql "update networks_tbl set id='$target_id' where id='$id' and deleted=0"

tables=$(get_relation_tables "network_id")
for table in $tables; do
if [ "$table" == "network_additional_wire_tbl" ]; then
exec_sql "update $table set network_id='$target_id' where network_id='$id'"
else
exec_sql "update $table set network_id='$target_id' where network_id='$id' and deleted=0"
fi
done

fi
done


function upgrade_managed_resources_table() {
local res_type=$1
local table_name=$2
local field=$3

echo "upgrade $table_name"
exec_sql "select name, id, external_id from $table_name where deleted=1 and length(external_id) > 0 and manager_id in (select id from cloudproviders_tbl where deleted=1 and provider='Huawei' and deleted_at > '$DATETIME')" | while read -r line; do
info=($(echo $line | tr " ", "\n"))
name=${info[0]}
target_id=${info[1]}
external_id=${info[2]}
id=$(exec_sql "select id from $table_name where deleted=0 and external_id='$external_id' and manager_id in (select id from cloudproviders_tbl where deleted=0 and provider='Huawei')")
if [ -n "$id" ]; then
target_id=$(change_uuid $table_name $target_id)
echo "change $res_type $name id from $id => $target_id"

exec_sql "update $table_name set id='$target_id' where id='$id' and deleted=0"

tables=$(get_relation_tables $field)
for table in $tables; do
exec_sql "update $table set $field='$target_id' where $field='$id' and deleted=0"
done
fi
done
}


upgrade_managed_resources_table "elasticcacheinstance" "elasticcacheinstances_tbl" "elasticcache_id"
upgrade_managed_resources_table "dbinstance" "dbinstances_tbl" "dbinstance_id"
upgrade_managed_resources_table "bucket" "buckets_tbl" "bucket_id"
upgrade_managed_resources_table "vpc" "vpcs_tbl" "vpc_id"
upgrade_managed_resources_table "cdn" "cdn_domains_tbl" "cdn_domain_id"
upgrade_managed_resources_table "dns" "dnszones_tbl" "dns_zone_id"
upgrade_managed_resources_table "elastic_search" "elastic_searchs_tbl" "elastic_search_id"
upgrade_managed_resources_table "eip" "elasticips_tbl" "eip_id"
upgrade_managed_resources_table "inter_vpc_network" "inter_vpc_networks_tbl" "inter_vpc_network_id"
upgrade_managed_resources_table "kafka" "kafkas_tbl" "kafka_id"
upgrade_managed_resources_table "loadbalancer" "loadbalancers_tbl" "loadbalancer_id"
upgrade_managed_resources_table "snapshot" "snapshots_tbl" "snapshot_id"
upgrade_managed_resources_table "sslcertificate" "sslcertificates_tbl" "sslcertificate_id"


3 changes: 2 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
## explicit; go 1.12
sigs.k8s.io/yaml
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231220111515-f4d6c15e4077
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231220111515-f4d6c15e4077 => /Users/quxuan/.go/src/yunion.io/x/cloudmux
## explicit; go 1.18
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
Expand Down Expand Up @@ -1625,3 +1625,4 @@ yunion.io/x/sqlchemy/backends/sqlite
# yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
## explicit; go 1.12
yunion.io/x/structarg
# yunion.io/x/cloudmux => /Users/quxuan/.go/src/yunion.io/x/cloudmux
4 changes: 0 additions & 4 deletions vendor/yunion.io/x/cloudmux/pkg/multicloud/hcso/modelarts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/yunion.io/x/cloudmux/pkg/multicloud/huawei/eip.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions vendor/yunion.io/x/cloudmux/pkg/multicloud/huawei/host.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f721ef7

Please sign in to comment.