From 6e4eb60e0bc2473d914a6cfeef32772489791ba8 Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Thu, 31 Mar 2022 18:01:02 +0900 Subject: [PATCH 1/4] Add Cloud Adaptive Network configuration when creating MCIS - Create `networking.go` - Add configureCloudAdaptiveNetwork() to `provisioning.go` - Update `go.mod` and `go.sum` --- conf/setup.env | 3 + go.mod | 4 +- go.sum | 22 ++++ src/core/mcis/networking.go | 210 ++++++++++++++++++++++++++++++++++ src/core/mcis/provisioning.go | 26 +++-- 5 files changed, 257 insertions(+), 8 deletions(-) create mode 100644 src/core/mcis/networking.go diff --git a/conf/setup.env b/conf/setup.env index 13f03bcce..2c30e2953 100644 --- a/conf/setup.env +++ b/conf/setup.env @@ -16,6 +16,9 @@ export DB_PASSWORD=cb_tumblebug export API_USERNAME=default export API_PASSWORD=default +export CB_NETWORK_SERVICE_ENDPOINT=localhost:8053 +export CB_NETWORK_ETCD_ENDPOINTS='["localhost:2379"]' + # Set period for auto control goroutine invocation export AUTOCONTROL_DURATION_MS=10000 diff --git a/go.mod b/go.mod index 2e389f1ab..e5f785e7c 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ replace ( require ( github.com/bramvdbogaerde/go-scp v1.0.0 github.com/cloud-barista/cb-dragonfly v0.4.4 + github.com/cloud-barista/cb-larva v0.0.10 github.com/cloud-barista/cb-log v0.5.0 github.com/cloud-barista/cb-spider v0.4.19 github.com/cloud-barista/cb-store v0.5.0 @@ -35,10 +36,11 @@ require ( github.com/stretchr/testify v1.7.0 github.com/swaggo/echo-swagger v1.3.0 github.com/swaggo/swag v1.7.9 - github.com/tidwall/gjson v1.10.2 + github.com/tidwall/gjson v1.11.0 github.com/tidwall/sjson v1.1.7 github.com/uber/jaeger-client-go v2.29.1+incompatible github.com/uber/jaeger-lib v2.4.1+incompatible // indirect + go.etcd.io/etcd v3.3.27+incompatible // indirect golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 google.golang.org/grpc v1.42.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 4eec44490..e6a31cc36 100644 --- a/go.sum +++ b/go.sum @@ -232,6 +232,10 @@ github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= github.com/cloud-barista/cb-dragonfly v0.4.4 h1:dnaTFbO2rarXZTB1I1U8OW++moRScgOoy2XCrdGL2Ho= github.com/cloud-barista/cb-dragonfly v0.4.4/go.mod h1:UllpEB0fBoEl5kUi7U/e5viwOFVxVA3pKhskds+vvVM= +github.com/cloud-barista/cb-larva v0.0.8 h1:otYqwiIC+Jqx3UhoeixNBnsMg/cwsZHSgfiZCs6ahTs= +github.com/cloud-barista/cb-larva v0.0.8/go.mod h1:w6odgcZmglNvjPvictv5KxppSaGMdbU9yoMRHeD8lxg= +github.com/cloud-barista/cb-larva v0.0.10 h1:twi6txmAhXpsji4bCrzVKgGi1x0gwr1q8wjMvLmdiZo= +github.com/cloud-barista/cb-larva v0.0.10/go.mod h1:Awo2l9VpeTfzjx6GhnAthtEMBEmhFZYvmN/GXpEuMK0= github.com/cloud-barista/cb-log v0.3.1/go.mod h1:C0KNV97sw8IoLSlNuSiCGDQIuS/wXJaZWV/6MOwc20c= github.com/cloud-barista/cb-log v0.4.0/go.mod h1:C0KNV97sw8IoLSlNuSiCGDQIuS/wXJaZWV/6MOwc20c= github.com/cloud-barista/cb-log v0.5.0 h1:WoUnXtNNNTA7wRgQa6sFNs57O3mLAOrh4aDHC4cU0CI= @@ -520,6 +524,7 @@ github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+ github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2KDnRCRMUi7GTA= github.com/go-openapi/validate v0.19.3/go.mod h1:90Vh6jjkTn+OT1Eefm0ZixWNFjhtOH7vS9k0lo6zwJo= github.com/go-openapi/validate v0.19.8/go.mod h1:8DJv2CVJQ6kGNpFW6eV9N3JviE1C85nY1c2z52x1Gk4= +github.com/go-ping/ping v0.0.0-20210506233800-ff8be3320020/go.mod h1:KmHOjTUmJh/l04ukqPoBWPEZr9jwN05h5NXQl5C+DyY= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= @@ -593,6 +598,7 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGw github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -712,6 +718,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.14.4/go.mod h1:6CwZWGDSPRJidgKAtJVvND6soZe6fT7iteq8wDPdhb0= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0 h1:rgxjzoDmDXw5q8HONgyHhBas4to0/XWRo/gPpJhsUNQ= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0/go.mod h1:qrJPVzv9YlhsrxJc3P/Q85nr0w1lIRikTl4JlhdDH5w= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= github.com/hashicorp/consul/api v1.4.0/go.mod h1:xc8u05kyMa3Wjr9eEAsIAo3dg8+LywT5E/Cl7cNS5nU= @@ -852,6 +860,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20160406211939-eadb3ce320cb/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= +github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= +github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= github.com/labstack/echo/v4 v4.0.0/go.mod h1:tZv7nai5buKSg5h/8E6zz4LsD/Dqh9/91Mvs7Z5Zyno= github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g= github.com/labstack/echo/v4 v4.1.14/go.mod h1:Q5KZ1vD3V5FEzjM79hjwVrC3ABr7F5IdM23bXQMRDGg= @@ -1242,6 +1252,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.206/go.mod h1: github.com/tidwall/gjson v1.8.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk= github.com/tidwall/gjson v1.10.2 h1:APbLGOM0rrEkd8WBw9C24nllro4ajFuJu0Sc9hRz8Bo= github.com/tidwall/gjson v1.10.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.11.0 h1:C16pk7tQNiH6VlCrtIXL1w8GaOsi1X3W8KDkE1BuYd4= +github.com/tidwall/gjson v1.11.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= @@ -1331,9 +1343,11 @@ go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489/go.mod h1:yVHk9ub3CSBatqGNg7GRmsnfLWtoW60w4eDYfh7vHDg= +go.etcd.io/etcd v3.3.27+incompatible/go.mod h1:yaeTdrJi5lOmYerz05bd8+V7KubZs8YSFZfzsF9A6aI= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= +go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0= go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= go.mongodb.org/mongo-driver v1.1.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= go.mongodb.org/mongo-driver v1.1.2/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= @@ -1377,6 +1391,7 @@ go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= +go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -1416,6 +1431,7 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 h1:71vQrMauZZhcTVK6KdYM+rklehEEwb3E+ZhaE5jrPrE= golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1505,6 +1521,7 @@ golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= @@ -1529,6 +1546,7 @@ golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211206223403-eba003a116a9/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -1545,6 +1563,7 @@ golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1674,6 +1693,7 @@ golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a h1:ppl5mZgokTT8uPkmYOyEUmPTr3ypaKkg5eFOGrAmxxE= @@ -1895,6 +1915,8 @@ google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxH google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= google.golang.org/genproto v0.0.0-20210719143636-1d5a45f8e492/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= +google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20211018162055-cf77aa76bad2/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211206220100-3cb06788ce7f h1:QH7+Ym+7e2XV1dZIHapkXoeqHyNaCzn6MNp3JBaYYUc= google.golang.org/genproto v0.0.0-20211206220100-3cb06788ce7f/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= diff --git a/src/core/mcis/networking.go b/src/core/mcis/networking.go new file mode 100644 index 000000000..657cc5385 --- /dev/null +++ b/src/core/mcis/networking.go @@ -0,0 +1,210 @@ +/* +Copyright 2019 The Cloud-Barista Authors. +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 mcis is to manage multi-cloud infra service +package mcis + +import ( + "encoding/json" + "errors" + "fmt" + "log" + "os" + "strings" + + model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" + nethelper "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/network-helper" + "github.com/cloud-barista/cb-tumblebug/src/core/common" + "github.com/cloud-barista/cb-tumblebug/src/core/mcir" + "github.com/go-resty/resty/v2" +) + +// configureCloudAdaptiveNetwork configures a cloud adaptive network to VMs in an MCIS +func configureCloudAdaptiveNetwork(nsId string, mcisInfo TbMcisInfo) error { + common.CBLog.Debug("Start.........") + + // Check cb-network endpoints + gRPCServiceEndpoint, etcdEndpoints, err := checkCBNetworkEndpoints() + if err != nil { + return err + } + + // Get subnet list + ipNetworksInMCIS, err := getSubnetsInMCIS(nsId, mcisInfo) + if err != nil { + return err + } + + // Get a propoer address space + cladnetDescription := fmt.Sprintf("A cladnet for %s", mcisInfo.Id) + cladnetSpec, err := createProperCloudAdaptiveNetwork(gRPCServiceEndpoint, ipNetworksInMCIS, mcisInfo.Id, cladnetDescription) + if err != nil { + log.Printf("Could not create a cloud adaptive network: %v\n", err) + return err + } + + log.Printf("Struct: %#v\n", cladnetSpec) + + // Install the cb-network agent + content, err := installCBNetworkAgentToMcis(nsId, mcisInfo.Id, etcdEndpoints, cladnetSpec.ID) + + if err != nil { + return err + } + common.PrintJsonPretty(content) + + common.CBLog.Debug("End.........") + return nil +} + +// checkCBNetworkEndpoints checks endpoints of cb-network service and etcd. +func checkCBNetworkEndpoints() (string, string, error) { + common.CBLog.Debug("Start.........") + + // Get an endpoint of cb-network service + serviceEndpoint := os.Getenv("CB_NETWORK_SERVICE_ENDPOINT") + if serviceEndpoint == "" { + return "", "", errors.New("could not load CB_NETWORK_SERVICE_ENDPOINT") + } + + // Get endpoints of cb-network etcd which should be accessible from the remote + etcdEndpoints := os.Getenv("CB_NETWORK_ETCD_ENDPOINTS") + if etcdEndpoints == "" { + return "", "", errors.New("could not load CB_NETWORK_ETCD_ENDPOINTS") + } + + common.CBLog.Debug("End.........") + return serviceEndpoint, etcdEndpoints, nil +} + +// getSubnetsInMCIS extracts all subnets in MCIS. +func getSubnetsInMCIS(nsId string, mcisInfo TbMcisInfo) ([]string, error) { + common.CBLog.Debug("Start.........") + + // Get IP Networks in MCIS + ipNetsInMCIS := make([]string, 0) + + for _, tbVmInfo := range mcisInfo.Vm { + // Get vNet info + res, err := mcir.GetResource(nsId, common.StrVNet, tbVmInfo.VNetId) + if err != nil { + return ipNetsInMCIS, err + } + + tempVNetInfo, ok := res.(mcir.TbVNetInfo) + if !ok { + return ipNetsInMCIS, err + } + + // Get IP Networks in a vNet + for _, SubnetInfo := range tempVNetInfo.SubnetInfoList { + ipNetsInMCIS = append(ipNetsInMCIS, SubnetInfo.IPv4_CIDR) + } + } + + // Trace + common.CBLog.Tracef("%#v", ipNetsInMCIS) + + common.CBLog.Debug("End.........") + return ipNetsInMCIS, nil +} + +// createProperCloudAdaptiveNetwork requests available IPv4 private address spaces and uses the recommended address space. +func createProperCloudAdaptiveNetwork(gRPCServiceEndpoint string, ipNetworks []string, cladnetName string, cladnetDescription string) (model.CLADNetSpecification, error) { + common.CBLog.Debug("Start.........") + + var spec model.CLADNetSpecification + + ipNetworksHolder := `{"ipNetworks": %s}` + tempJSON, _ := json.Marshal(ipNetworks) + ipNetworksString := fmt.Sprintf(ipNetworksHolder, string(tempJSON)) + fmt.Println(ipNetworksString) + + client := resty.New() + + // Request a recommendation of available IPv4 private address spaces. + resp, err := client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetBody(ipNetworksString). + Post(fmt.Sprintf("http://%s/v1/cladnet/available-ipv4-address-spaces", gRPCServiceEndpoint)) + // Output print + log.Printf("\nError: %v\n", err) + log.Printf("Time: %v\n", resp.Time()) + log.Printf("Body: %v\n", resp) + + if err != nil { + log.Printf("Could not request: %v\n", err) + return model.CLADNetSpecification{}, err + } + + var availableIPv4PrivateAddressSpaces nethelper.AvailableIPv4PrivateAddressSpaces + + json.Unmarshal(resp.Body(), &availableIPv4PrivateAddressSpaces) + log.Printf("%+v\n", availableIPv4PrivateAddressSpaces) + log.Printf("RecommendedIpv4PrivateAddressSpace: %#v", availableIPv4PrivateAddressSpaces.RecommendedIPv4PrivateAddressSpace) + + cladnetSpecHolder := `{"id": "", "name": "%s", "ipv4AddressSpace": "%s", "description": "%s"}` + cladnetSpecString := fmt.Sprintf(cladnetSpecHolder, + cladnetName, availableIPv4PrivateAddressSpaces.RecommendedIPv4PrivateAddressSpace, cladnetDescription) + log.Printf("%#v\n", cladnetSpecString) + + // Request to create a Cloud Adaptive Network + resp, err = client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetBody(cladnetSpecString). + Post(fmt.Sprintf("http://%s/v1/cladnet", gRPCServiceEndpoint)) + // Output print + log.Printf("\nError: %v\n", err) + log.Printf("Time: %v\n", resp.Time()) + log.Printf("Body: %v\n", resp) + + if err != nil { + log.Printf("Could not request: %v\n", err) + return model.CLADNetSpecification{}, err + } + + json.Unmarshal(resp.Body(), &spec) + log.Printf("%#v\n", spec) + + common.CBLog.Debug("End.........") + return spec, nil +} + +// installCBNetworkAgentToMcis installs cb-network agent to VMs in an MCIS by the remote command +func installCBNetworkAgentToMcis(nsId string, mcisId string, etcdEndpoints string, cladnetID string) ([]SshCmdResult, error) { + common.CBLog.Debug("Start.........") + + // SSH command to install cb-network agents + placeHolderCommand := `wget https://raw.githubusercontent.com/cloud-barista/cb-larva/develop/poc-cb-net/scripts/1.deploy-cb-network-agent.sh -O ~/1.deploy-cb-network-agent.sh; chmod +x ~/1.deploy-cb-network-agent.sh; source ~/1.deploy-cb-network-agent.sh '%s' %s` + + additionalEncodedString := strings.Replace(etcdEndpoints, "\"", "\\\"", -1) + command := fmt.Sprintf(placeHolderCommand, additionalEncodedString, cladnetID) + + // Replace given parameter with the installation cmd + mcisCmdReq := &McisCmdReq{} + mcisCmdReq.UserName = "cb-user" // this MCIS user name is temporal code. Need to improve. + mcisCmdReq.Command = command + + sshCmdResult, err := RemoteCommandToMcis(nsId, mcisId, mcisCmdReq) + + if err != nil { + temp := []SshCmdResult{} + common.CBLog.Error(err) + return temp, err + } + + common.CBLog.Debug("End.........") + return sshCmdResult, nil +} diff --git a/src/core/mcis/provisioning.go b/src/core/mcis/provisioning.go index 03b66e1c7..ab9d1ab31 100644 --- a/src/core/mcis/provisioning.go +++ b/src/core/mcis/provisioning.go @@ -933,15 +933,25 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) fmt.Println("[MCIS has been created]" + mcisId) //common.PrintJsonPretty(mcisTmp) - // Install CB-Dragonfly monitoring agent + // The below will be added to 'TbMcisInfo struct{}' + // // ConfigureCloudAdaptiveNetwork is an option to configure Cloud Adaptive Network (CLADNet) ([yes/no] default:yes) + // ConfigureCloudAdaptiveNetwork string `json:"configureCloudAdaptiveNetwork" example:"yes" default:"yes" enums:"yes,no"` // yes or no + + if (req.InstallMonAgent != "no" || option != "register") || true { // mcisTmp.ConfigureCloudAdaptiveNetwork != "no" { + // Sleep for 60 seconds for a safe DF agent installation. + fmt.Printf("\n\n[Info] Sleep for 60 seconds for safe CB-Dragonfly Agent installation or Cloud Adaptive Network configuration.\n\n") + time.Sleep(60 * time.Second) + } - fmt.Printf("[Init monitoring agent] for %+v\n - req.InstallMonAgent: %+v\n\n", mcisTmp.Id, req.InstallMonAgent) + // Install CB-Dragonfly monitoring agent mcisTmp.InstallMonAgent = req.InstallMonAgent UpdateMcisInfo(nsId, mcisTmp) if req.InstallMonAgent != "no" || option != "register" { + fmt.Printf("[Init monitoring agent] for %+v\n - req.InstallMonAgent: %+v\n\n", mcisTmp.Id, req.InstallMonAgent) + check := CheckDragonflyEndpoint() if check != nil { fmt.Printf("\n\n[Warring] CB-Dragonfly is not available\n\n") @@ -949,11 +959,6 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) reqToMon := &McisCmdReq{} reqToMon.UserName = "cb-user" // this MCIS user name is temporal code. Need to improve. - fmt.Printf("\n===========================\n") - // Sleep for 60 seconds for a safe DF agent installation. - fmt.Printf("\n\n[Info] Sleep for 60 seconds for safe CB-Dragonfly Agent installation.\n") - time.Sleep(60 * time.Second) - fmt.Printf("\n[InstallMonitorAgentToMcis]\n\n") content, err := InstallMonitorAgentToMcis(nsId, mcisId, mcisTmp.SystemLabel, reqToMon) if err != nil { @@ -965,6 +970,13 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) } } + // Configure Cloud Adaptive Network + if true { //mcisTmp.ConfigureCloudAdaptiveNetwork != "no" { + + fmt.Printf("\n[Configure Cloud Adaptive Network] for %+v\n - req.ConfigureCloudAdaptiveNetwork: %+v\n\n", mcisId, "yes") //mcisTmp.ConfigureCloudAdaptiveNetwork) + configureCloudAdaptiveNetwork(nsId, mcisTmp) + } + mcisResult, err := GetMcisInfo(nsId, mcisId) if err != nil { common.CBLog.Error(err) From b4ff1d31444ec16d37e286257947fa955ebd6bee Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Fri, 1 Apr 2022 20:00:07 +0900 Subject: [PATCH 2/4] Update for API-first development - Reset `provisioning.go` and add variables related to the cb-network agent - Add a REST API to configure Cloud Adaptive Network to MCIS --- src/api/rest/server/mcis/network.go | 97 +++++++ src/api/rest/server/server.go | 3 + src/core/mcis/network.go | 383 ++++++++++++++++++++++++++++ src/core/mcis/networking.go | 210 --------------- src/core/mcis/provisioning.go | 33 +-- 5 files changed, 497 insertions(+), 229 deletions(-) create mode 100644 src/api/rest/server/mcis/network.go create mode 100644 src/core/mcis/network.go delete mode 100644 src/core/mcis/networking.go diff --git a/src/api/rest/server/mcis/network.go b/src/api/rest/server/mcis/network.go new file mode 100644 index 000000000..a02129a66 --- /dev/null +++ b/src/api/rest/server/mcis/network.go @@ -0,0 +1,97 @@ +/* +Copyright 2019 The Cloud-Barista Authors. +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 mcis is to handle REST API for mcis +package mcis + +import ( + "net/http" + + "github.com/cloud-barista/cb-tumblebug/src/core/common" + "github.com/cloud-barista/cb-tumblebug/src/core/mcis" + "github.com/labstack/echo/v4" +) + +// RestPostConfigureCloudAdaptiveNetworkToMcis godoc +// @Summary Configure Cloud Adaptive Network (cb-network agent) to MCIS +// @Description Configure Cloud Adaptive Network (cb-network agent) to MCIS +// @Tags [Infra service] MCIS Cloud Adaptive Network (for developer) +// @Accept json +// @Produce json +// @Param nsId path string true "Namespace ID" default(ns01) +// @Param mcisId path string true "MCIS ID" default(mcis01) +// @Param networkReq body mcis.NetworkReq true "Details for the network request body" +// @Success 200 {object} mcis.AgentInstallContentWrapper +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /ns/{nsId}/network/mcis/{mcisId} [post] +func RestPostConfigureCloudAdaptiveNetworkToMcis(c echo.Context) error { + + nsId := c.Param("nsId") + mcisId := c.Param("mcisId") + + netReq := &mcis.NetworkReq{} + if err := c.Bind(netReq); err != nil { + return err + } + + contents, err := mcis.ConfigureCloudAdaptiveNetwork(nsId, mcisId, netReq) + + if err != nil { + common.CBLog.Error(err) + return err + + } + + // mcisTmpSystemLabel := mcis.DefaultSystemLabel + // content, err := mcis.InstallMonitorAgentToMcis(nsId, mcisId, mcisTmpSystemLabel, req) + // if err != nil { + // common.CBLog.Error(err) + // return err + // } + + return c.JSON(http.StatusOK, contents) +} + +// // RestGetMonitorData godoc +// // @Summary Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network) +// // @Description Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network) +// // @Tags [Infra service] MCIS Resource monitor (for developer) +// // @Accept json +// // @Produce json +// // @Param nsId path string true "Namespace ID" default(ns01) +// // @Param mcisId path string true "MCIS ID" default(mcis01) +// // @Param metric path string true "Metric type: cpu, memory, disk, network" +// // @Success 200 {object} mcis.MonResultSimpleResponse +// // @Failure 404 {object} common.SimpleMsg +// // @Failure 500 {object} common.SimpleMsg +// // @Router /ns/{nsId}/monitoring/mcis/{mcisId}/metric/{metric} [get] +// func RestGetMonitorData(c echo.Context) error { + +// nsId := c.Param("nsId") +// mcisId := c.Param("mcisId") +// metric := c.Param("metric") + +// req := &mcis.McisCmdReq{} +// if err := c.Bind(req); err != nil { +// return err +// } + +// content, err := mcis.GetMonitoringData(nsId, mcisId, metric) +// if err != nil { +// common.CBLog.Error(err) +// return err +// } + +// return c.JSON(http.StatusOK, content) +// } diff --git a/src/api/rest/server/server.go b/src/api/rest/server/server.go index da9450063..4544f8d21 100644 --- a/src/api/rest/server/server.go +++ b/src/api/rest/server/server.go @@ -200,6 +200,9 @@ func RunServer(port string) { g.POST("/:nsId/monitoring/install/mcis/:mcisId", rest_mcis.RestPostInstallMonitorAgentToMcis) g.GET("/:nsId/monitoring/mcis/:mcisId/metric/:metric", rest_mcis.RestGetMonitorData) + // MCIS Cloud Adaptive Network (for developer) + g.POST("/:nsId/network/mcis/:mcisId", rest_mcis.RestPostConfigureCloudAdaptiveNetworkToMcis) + //MCIR Management g.POST("/:nsId/resources/image", rest_mcir.RestPostImage) g.GET("/:nsId/resources/image/:resourceId", rest_mcir.RestGetResource) diff --git a/src/core/mcis/network.go b/src/core/mcis/network.go new file mode 100644 index 000000000..84ff6f911 --- /dev/null +++ b/src/core/mcis/network.go @@ -0,0 +1,383 @@ +/* +Copyright 2019 The Cloud-Barista Authors. +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 mcis is to manage multi-cloud infra service +package mcis + +import ( + "encoding/json" + "fmt" + "log" + "strings" + "sync" + + model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" + nethelper "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/network-helper" + "github.com/cloud-barista/cb-tumblebug/src/core/common" + "github.com/cloud-barista/cb-tumblebug/src/core/mcir" + "github.com/go-resty/resty/v2" +) + +// NetworkReq is a struct for a request to configure Cloud Adaptive Network +type NetworkReq struct { + ServiceEndpoint string `json:"serviceEndpoint" example:"localhost:8053" default:"localhost:8053"` + EtcdEndpoints []string `json:"etcdEndpoints" example:"[\"PUBLIC_IP_1:2379\", \"PUBLIC_IP_2:2379\", ...]"` +} + +// ConfigureCloudAdaptiveNetwork configures a cloud adaptive network to VMs in an MCIS +func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkReq) (AgentInstallContentWrapper, error) { + common.CBLog.Debug("Start.........") + + if err := common.CheckString(nsId); err != nil { + common.CBLog.Error(err) + return AgentInstallContentWrapper{}, err + } + + if err := common.CheckString(mcisId); err != nil { + common.CBLog.Error(err) + return AgentInstallContentWrapper{}, err + } + + if _, err := CheckMcis(nsId, mcisId); err != nil { + return AgentInstallContentWrapper{}, err + } + + // Get a list of VM ID + vmIdList, err := ListVmId(nsId, mcisId) + if err != nil { + common.CBLog.Error(err) + return AgentInstallContentWrapper{}, err + } + + // // Check cb-network endpoints + // networkServiceEndpoint, etcdEndpoints, err := checkCBNetworkEndpoints() + // if err != nil { + // return cladnetSpec, err + // } + + // Get Cloud Adaptive Network + cladnetSpec, err := getCloudAdaptiveNetwork(netReq.ServiceEndpoint, mcisId) + if err != nil { + common.CBLog.Error(err) + return AgentInstallContentWrapper{}, err + } + + // if not exist + if cladnetSpec.ID == "" { + + // Get subnet list + ipNetworksInMCIS, err := getSubnetsInMCIS(nsId, mcisId, vmIdList) + if err != nil { + return AgentInstallContentWrapper{}, err + } + + // Get a propoer address space + cladnetDescription := fmt.Sprintf("A cladnet for %s", mcisId) + cladnetSpec, err = createProperCloudAdaptiveNetwork(netReq.ServiceEndpoint, ipNetworksInMCIS, mcisId, cladnetDescription) + if err != nil { + common.CBLog.Printf("could not create a cloud adaptive network: %v\n", err) + return AgentInstallContentWrapper{}, err + } + } + + common.CBLog.Printf("Struct: %#v\n", cladnetSpec) + + // Prepare the installation command + etcdEndpointsJSON, _ := json.Marshal(netReq.EtcdEndpoints) + command := makeInstallationCommand(string(etcdEndpointsJSON), cladnetSpec.ID) + + // Replace given parameter with the installation cmd + mcisCmdReq := McisCmdReq{} + mcisCmdReq.UserName = "cb-user" // this MCIS user name is temporal code. Need to improve. + mcisCmdReq.Command = command + + //// Install the cb-network agent to MCIS + // sshCmdResults, err := installCBNetworkAgentToMcis(nsId, mcisId, mcisCmdReq) + + // Install cb-network agents in parallel + var wg *sync.WaitGroup + chanResults := make(chan SshCmdResult) + + var sshCmdResults []SshCmdResult + + for _, vmId := range vmIdList { + wg.Add(1) + go func(nsId, mcisId, vmId string, mcisCmdReq McisCmdReq, chanResults chan SshCmdResult) { + defer wg.Done() + + // Check NetworkAgentStatus + vmObject, _ := GetVmObject(nsId, mcisId, vmId) + fmt.Println("NetworkAgentStatus : " + vmObject.NetworkAgentStatus) + + // Skip if in installing or installed status) + if vmObject.NetworkAgentStatus != "installed" && vmObject.NetworkAgentStatus != "installing" { + + vmObj, _ := GetVmObject(nsId, mcisId, vmId) + vmObj.NetworkAgentStatus = "installing" + + SshCmdResult, err := installCBNetworkAgentToVM(nsId, mcisId, vmId, mcisCmdReq) + if err != nil { + vmObject.NetworkAgentStatus = "installed" + } else { + vmObject.NetworkAgentStatus = "failed" + } + + chanResults <- SshCmdResult + } + + }(nsId, mcisId, vmId, mcisCmdReq, chanResults) + } + + go func() { + wg.Wait() + close(chanResults) + }() + + // Collect the results of installing the cb-network agents in parallel + contents := AgentInstallContentWrapper{} + for result := range chanResults { + tempContent := AgentInstallContent{} + tempContent.McisId = mcisId + tempContent.VmId = result.VmId + tempContent.VmIp = result.VmIp + tempContent.Result = result.Result + + contents.ResultArray = append(contents.ResultArray, tempContent) + } + common.PrintJsonPretty(sshCmdResults) + + common.CBLog.Debug("End.........") + return contents, nil +} + +// // checkCBNetworkEndpoints checks endpoints of cb-network service and etcd. +// func checkCBNetworkEndpoints() (string, string, error) { +// common.CBLog.Debug("Start.........") + +// // Get an endpoint of cb-network service +// serviceEndpoint := os.Getenv("CB_NETWORK_SERVICE_ENDPOINT") +// if serviceEndpoint == "" { +// return "", "", errors.New("could not load CB_NETWORK_SERVICE_ENDPOINT") +// } + +// // Get endpoints of cb-network etcd which should be accessible from the remote +// etcdEndpoints := os.Getenv("CB_NETWORK_ETCD_ENDPOINTS") +// if etcdEndpoints == "" { +// return "", "", errors.New("could not load CB_NETWORK_ETCD_ENDPOINTS") +// } + +// common.CBLog.Debug("End.........") +// return serviceEndpoint, etcdEndpoints, nil +// } + +// getCloudAdaptiveNetwork retrieves a Cloud Adaptive Network +func getCloudAdaptiveNetwork(networkServiceEndpoint string, cladnetId string) (model.CLADNetSpecification, error) { + common.CBLog.Debug("Start.........") + var cladnetSpec model.CLADNetSpecification + + client := resty.New() + + // Request a recommendation of available IPv4 private address spaces. + resp, err := client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetPathParams(map[string]string{ + "cladnet-id": cladnetId, + }). + Get(fmt.Sprintf("http://%s/v1/cladnet/{cladnet-id}", networkServiceEndpoint)) + // Output print + log.Printf("\nError: %v\n", err) + common.CBLog.Printf("Time: %v\n", resp.Time()) + common.CBLog.Printf("Body: %v\n", resp) + + if err != nil { + common.CBLog.Error(err) + return model.CLADNetSpecification{}, err + } + + common.CBLog.Debug("End.........") + return cladnetSpec, nil +} + +// getSubnetsInMCIS extracts all subnets in MCIS. +func getSubnetsInMCIS(nsId string, mcisId string, vmList []string) ([]string, error) { + common.CBLog.Debug("Start.........") + + ipNetsInMCIS := make([]string, 0) + + for _, vmId := range vmList { + + // Get vNet info + tbVmInfo, err := GetVmObject(nsId, mcisId, vmId) + if err != nil { + common.CBLog.Error(err) + return ipNetsInMCIS, err + } + + // getVNet + res, err := mcir.GetResource(nsId, common.StrVNet, tbVmInfo.VNetId) + if err != nil { + common.CBLog.Error(err) + return ipNetsInMCIS, err + } + + // type casting + tempVNetInfo, ok := res.(mcir.TbVNetInfo) + if !ok { + common.CBLog.Error(err) + return ipNetsInMCIS, err + } + + // Get IP Networks in a vNet + for _, SubnetInfo := range tempVNetInfo.SubnetInfoList { + ipNetsInMCIS = append(ipNetsInMCIS, SubnetInfo.IPv4_CIDR) + } + } + + // Trace + common.CBLog.Tracef("%#v", ipNetsInMCIS) + + common.CBLog.Debug("End.........") + return ipNetsInMCIS, nil +} + +// createProperCloudAdaptiveNetwork requests available IPv4 private address spaces and uses the recommended address space. +func createProperCloudAdaptiveNetwork(networkServiceEndpoint string, ipNetworks []string, cladnetName string, cladnetDescription string) (model.CLADNetSpecification, error) { + common.CBLog.Debug("Start.........") + + var spec model.CLADNetSpecification + + ipNetworksHolder := `{"ipNetworks": %s}` + tempJSON, _ := json.Marshal(ipNetworks) + ipNetworksString := fmt.Sprintf(ipNetworksHolder, string(tempJSON)) + fmt.Println(ipNetworksString) + + client := resty.New() + + // Request a recommendation of available IPv4 private address spaces. + resp, err := client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetBody(ipNetworksString). + Post(fmt.Sprintf("http://%s/v1/cladnet/available-ipv4-address-spaces", networkServiceEndpoint)) + // Output print + common.CBLog.Printf("\nError: %v\n", err) + common.CBLog.Printf("Time: %v\n", resp.Time()) + common.CBLog.Printf("Body: %v\n", resp) + + if err != nil { + common.CBLog.Printf("Could not request: %v\n", err) + return model.CLADNetSpecification{}, err + } + + var availableIPv4PrivateAddressSpaces nethelper.AvailableIPv4PrivateAddressSpaces + + json.Unmarshal(resp.Body(), &availableIPv4PrivateAddressSpaces) + common.CBLog.Printf("%+v\n", availableIPv4PrivateAddressSpaces) + common.CBLog.Printf("RecommendedIpv4PrivateAddressSpace: %#v", availableIPv4PrivateAddressSpaces.RecommendedIPv4PrivateAddressSpace) + + cladnetSpecHolder := `{"id": "", "name": "%s", "ipv4AddressSpace": "%s", "description": "%s"}` + cladnetSpecString := fmt.Sprintf(cladnetSpecHolder, + cladnetName, availableIPv4PrivateAddressSpaces.RecommendedIPv4PrivateAddressSpace, cladnetDescription) + common.CBLog.Printf("%#v\n", cladnetSpecString) + + // Request to create a Cloud Adaptive Network + resp, err = client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetBody(cladnetSpecString). + Post(fmt.Sprintf("http://%s/v1/cladnet", networkServiceEndpoint)) + // Output print + common.CBLog.Printf("\nError: %v\n", err) + common.CBLog.Printf("Time: %v\n", resp.Time()) + common.CBLog.Printf("Body: %v\n", resp) + + if err != nil { + common.CBLog.Printf("Could not request: %v\n", err) + return model.CLADNetSpecification{}, err + } + + json.Unmarshal(resp.Body(), &spec) + common.CBLog.Printf("%#v\n", spec) + + common.CBLog.Debug("End.........") + return spec, nil +} + +func makeInstallationCommand(etcdEndpoints, cladnetId string) string { + // SSH command to install cb-network agents + placeHolderCommand := `wget https://raw.githubusercontent.com/cloud-barista/cb-larva/develop/poc-cb-net/scripts/1.deploy-cb-network-agent.sh -O ~/1.deploy-cb-network-agent.sh; chmod +x ~/1.deploy-cb-network-agent.sh; source ~/1.deploy-cb-network-agent.sh '%s' %s` + + additionalEncodedString := strings.Replace(etcdEndpoints, "\"", "\\\"", -1) + command := fmt.Sprintf(placeHolderCommand, additionalEncodedString, cladnetId) + + return command +} + +// installCBNetworkAgentToMcis installs cb-network agent to VMs in an MCIS by the remote command +func installCBNetworkAgentToVM(nsId, mcisId, vmId string, mcisCmdReq McisCmdReq) (SshCmdResult, error) { + common.CBLog.Debug("Start.........") + + vmIp, sshPort := GetVmIp(nsId, mcisId, vmId) + + // find vaild username + userName, sshKey, err := VerifySshUserName(nsId, mcisId, vmId, vmIp, sshPort, mcisCmdReq.UserName) + // Eventhough VerifySshUserName is not complete, Try RunRemoteCommand + // With RunRemoteCommand, error will be checked again + if err == nil { + // Just logging the error (but it is net a faultal ) + common.CBLog.Info(err) + } + fmt.Println("") + fmt.Println("[SSH] " + mcisId + "." + vmId + "(" + vmIp + ")" + " with userName: " + userName) + fmt.Println("[CMD] " + mcisCmdReq.Command) + fmt.Println("") + + result, err := RunRemoteCommand(vmIp, sshPort, userName, sshKey, mcisCmdReq.Command) + + sshResultTmp := SshCmdResult{} + sshResultTmp.McisId = "" + sshResultTmp.VmId = vmId + sshResultTmp.VmIp = vmIp + + if err != nil { + sshResultTmp.Result = ("[ERROR: " + err.Error() + "]\n " + *result) + sshResultTmp.Err = err + } else { + fmt.Println("[Begin] SSH Output") + fmt.Println(*result) + fmt.Println("[end] SSH Output") + + sshResultTmp.Result = *result + sshResultTmp.Err = nil + } + + common.CBLog.Debug("End.........") + return sshResultTmp, err +} + +// // installCBNetworkAgentToMcis installs cb-network agent to VMs in an MCIS by the remote command +// func installCBNetworkAgentToMcis(nsId, mcisId string, mcisCmdReq McisCmdReq) ([]SshCmdResult, error) { +// common.CBLog.Debug("Start.........") + +// sshCmdResult, err := RemoteCommandToMcis(nsId, mcisId, &mcisCmdReq) + +// if err != nil { +// temp := []SshCmdResult{} +// common.CBLog.Error(err) +// return temp, err +// } + +// common.CBLog.Debug("End.........") +// return sshCmdResult, nil +// } diff --git a/src/core/mcis/networking.go b/src/core/mcis/networking.go deleted file mode 100644 index 657cc5385..000000000 --- a/src/core/mcis/networking.go +++ /dev/null @@ -1,210 +0,0 @@ -/* -Copyright 2019 The Cloud-Barista Authors. -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 mcis is to manage multi-cloud infra service -package mcis - -import ( - "encoding/json" - "errors" - "fmt" - "log" - "os" - "strings" - - model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" - nethelper "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/network-helper" - "github.com/cloud-barista/cb-tumblebug/src/core/common" - "github.com/cloud-barista/cb-tumblebug/src/core/mcir" - "github.com/go-resty/resty/v2" -) - -// configureCloudAdaptiveNetwork configures a cloud adaptive network to VMs in an MCIS -func configureCloudAdaptiveNetwork(nsId string, mcisInfo TbMcisInfo) error { - common.CBLog.Debug("Start.........") - - // Check cb-network endpoints - gRPCServiceEndpoint, etcdEndpoints, err := checkCBNetworkEndpoints() - if err != nil { - return err - } - - // Get subnet list - ipNetworksInMCIS, err := getSubnetsInMCIS(nsId, mcisInfo) - if err != nil { - return err - } - - // Get a propoer address space - cladnetDescription := fmt.Sprintf("A cladnet for %s", mcisInfo.Id) - cladnetSpec, err := createProperCloudAdaptiveNetwork(gRPCServiceEndpoint, ipNetworksInMCIS, mcisInfo.Id, cladnetDescription) - if err != nil { - log.Printf("Could not create a cloud adaptive network: %v\n", err) - return err - } - - log.Printf("Struct: %#v\n", cladnetSpec) - - // Install the cb-network agent - content, err := installCBNetworkAgentToMcis(nsId, mcisInfo.Id, etcdEndpoints, cladnetSpec.ID) - - if err != nil { - return err - } - common.PrintJsonPretty(content) - - common.CBLog.Debug("End.........") - return nil -} - -// checkCBNetworkEndpoints checks endpoints of cb-network service and etcd. -func checkCBNetworkEndpoints() (string, string, error) { - common.CBLog.Debug("Start.........") - - // Get an endpoint of cb-network service - serviceEndpoint := os.Getenv("CB_NETWORK_SERVICE_ENDPOINT") - if serviceEndpoint == "" { - return "", "", errors.New("could not load CB_NETWORK_SERVICE_ENDPOINT") - } - - // Get endpoints of cb-network etcd which should be accessible from the remote - etcdEndpoints := os.Getenv("CB_NETWORK_ETCD_ENDPOINTS") - if etcdEndpoints == "" { - return "", "", errors.New("could not load CB_NETWORK_ETCD_ENDPOINTS") - } - - common.CBLog.Debug("End.........") - return serviceEndpoint, etcdEndpoints, nil -} - -// getSubnetsInMCIS extracts all subnets in MCIS. -func getSubnetsInMCIS(nsId string, mcisInfo TbMcisInfo) ([]string, error) { - common.CBLog.Debug("Start.........") - - // Get IP Networks in MCIS - ipNetsInMCIS := make([]string, 0) - - for _, tbVmInfo := range mcisInfo.Vm { - // Get vNet info - res, err := mcir.GetResource(nsId, common.StrVNet, tbVmInfo.VNetId) - if err != nil { - return ipNetsInMCIS, err - } - - tempVNetInfo, ok := res.(mcir.TbVNetInfo) - if !ok { - return ipNetsInMCIS, err - } - - // Get IP Networks in a vNet - for _, SubnetInfo := range tempVNetInfo.SubnetInfoList { - ipNetsInMCIS = append(ipNetsInMCIS, SubnetInfo.IPv4_CIDR) - } - } - - // Trace - common.CBLog.Tracef("%#v", ipNetsInMCIS) - - common.CBLog.Debug("End.........") - return ipNetsInMCIS, nil -} - -// createProperCloudAdaptiveNetwork requests available IPv4 private address spaces and uses the recommended address space. -func createProperCloudAdaptiveNetwork(gRPCServiceEndpoint string, ipNetworks []string, cladnetName string, cladnetDescription string) (model.CLADNetSpecification, error) { - common.CBLog.Debug("Start.........") - - var spec model.CLADNetSpecification - - ipNetworksHolder := `{"ipNetworks": %s}` - tempJSON, _ := json.Marshal(ipNetworks) - ipNetworksString := fmt.Sprintf(ipNetworksHolder, string(tempJSON)) - fmt.Println(ipNetworksString) - - client := resty.New() - - // Request a recommendation of available IPv4 private address spaces. - resp, err := client.R(). - SetHeader("Content-Type", "application/json"). - SetHeader("Accept", "application/json"). - SetBody(ipNetworksString). - Post(fmt.Sprintf("http://%s/v1/cladnet/available-ipv4-address-spaces", gRPCServiceEndpoint)) - // Output print - log.Printf("\nError: %v\n", err) - log.Printf("Time: %v\n", resp.Time()) - log.Printf("Body: %v\n", resp) - - if err != nil { - log.Printf("Could not request: %v\n", err) - return model.CLADNetSpecification{}, err - } - - var availableIPv4PrivateAddressSpaces nethelper.AvailableIPv4PrivateAddressSpaces - - json.Unmarshal(resp.Body(), &availableIPv4PrivateAddressSpaces) - log.Printf("%+v\n", availableIPv4PrivateAddressSpaces) - log.Printf("RecommendedIpv4PrivateAddressSpace: %#v", availableIPv4PrivateAddressSpaces.RecommendedIPv4PrivateAddressSpace) - - cladnetSpecHolder := `{"id": "", "name": "%s", "ipv4AddressSpace": "%s", "description": "%s"}` - cladnetSpecString := fmt.Sprintf(cladnetSpecHolder, - cladnetName, availableIPv4PrivateAddressSpaces.RecommendedIPv4PrivateAddressSpace, cladnetDescription) - log.Printf("%#v\n", cladnetSpecString) - - // Request to create a Cloud Adaptive Network - resp, err = client.R(). - SetHeader("Content-Type", "application/json"). - SetHeader("Accept", "application/json"). - SetBody(cladnetSpecString). - Post(fmt.Sprintf("http://%s/v1/cladnet", gRPCServiceEndpoint)) - // Output print - log.Printf("\nError: %v\n", err) - log.Printf("Time: %v\n", resp.Time()) - log.Printf("Body: %v\n", resp) - - if err != nil { - log.Printf("Could not request: %v\n", err) - return model.CLADNetSpecification{}, err - } - - json.Unmarshal(resp.Body(), &spec) - log.Printf("%#v\n", spec) - - common.CBLog.Debug("End.........") - return spec, nil -} - -// installCBNetworkAgentToMcis installs cb-network agent to VMs in an MCIS by the remote command -func installCBNetworkAgentToMcis(nsId string, mcisId string, etcdEndpoints string, cladnetID string) ([]SshCmdResult, error) { - common.CBLog.Debug("Start.........") - - // SSH command to install cb-network agents - placeHolderCommand := `wget https://raw.githubusercontent.com/cloud-barista/cb-larva/develop/poc-cb-net/scripts/1.deploy-cb-network-agent.sh -O ~/1.deploy-cb-network-agent.sh; chmod +x ~/1.deploy-cb-network-agent.sh; source ~/1.deploy-cb-network-agent.sh '%s' %s` - - additionalEncodedString := strings.Replace(etcdEndpoints, "\"", "\\\"", -1) - command := fmt.Sprintf(placeHolderCommand, additionalEncodedString, cladnetID) - - // Replace given parameter with the installation cmd - mcisCmdReq := &McisCmdReq{} - mcisCmdReq.UserName = "cb-user" // this MCIS user name is temporal code. Need to improve. - mcisCmdReq.Command = command - - sshCmdResult, err := RemoteCommandToMcis(nsId, mcisId, mcisCmdReq) - - if err != nil { - temp := []SshCmdResult{} - common.CBLog.Error(err) - return temp, err - } - - common.CBLog.Debug("End.........") - return sshCmdResult, nil -} diff --git a/src/core/mcis/provisioning.go b/src/core/mcis/provisioning.go index ab9d1ab31..00e824931 100644 --- a/src/core/mcis/provisioning.go +++ b/src/core/mcis/provisioning.go @@ -167,6 +167,9 @@ type TbMcisInfo struct { // InstallMonAgent Option for CB-Dragonfly agent installation ([yes/no] default:yes) InstallMonAgent string `json:"installMonAgent" example:"yes" default:"yes" enums:"yes,no"` // yes or no + // ConfigureCloudAdaptiveNetwork is an option to configure Cloud Adaptive Network (CLADNet) ([yes/no] default:yes) + ConfigureCloudAdaptiveNetwork string `json:"configureCloudAdaptiveNetwork" example:"yes" default:"yes" enums:"yes,no"` // yes or no + // Label is for describing the mcis in a keyword (any string can be used) Label string `json:"label" example:"User custom label"` @@ -310,6 +313,9 @@ type TbVmInfo struct { // Montoring agent status MonAgentStatus string `json:"monAgentStatus" example:"[installed, notInstalled, failed]"` // yes or no// installed, notInstalled, failed + // NetworkAgent status + NetworkAgentStatus string `json:"networkAgentStatus" example:"[notInstalled, installing, installed, failed]"` // notInstalled, installing, installed, failed + // Latest system message such as error message SystemMessage string `json:"systemMessage" example:"Failed because ..." default:""` // systeam-given string message @@ -933,25 +939,15 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) fmt.Println("[MCIS has been created]" + mcisId) //common.PrintJsonPretty(mcisTmp) - // The below will be added to 'TbMcisInfo struct{}' - // // ConfigureCloudAdaptiveNetwork is an option to configure Cloud Adaptive Network (CLADNet) ([yes/no] default:yes) - // ConfigureCloudAdaptiveNetwork string `json:"configureCloudAdaptiveNetwork" example:"yes" default:"yes" enums:"yes,no"` // yes or no - - if (req.InstallMonAgent != "no" || option != "register") || true { // mcisTmp.ConfigureCloudAdaptiveNetwork != "no" { - // Sleep for 60 seconds for a safe DF agent installation. - fmt.Printf("\n\n[Info] Sleep for 60 seconds for safe CB-Dragonfly Agent installation or Cloud Adaptive Network configuration.\n\n") - time.Sleep(60 * time.Second) - } - // Install CB-Dragonfly monitoring agent + fmt.Printf("[Init monitoring agent] for %+v\n - req.InstallMonAgent: %+v\n\n", mcisTmp.Id, req.InstallMonAgent) + mcisTmp.InstallMonAgent = req.InstallMonAgent UpdateMcisInfo(nsId, mcisTmp) if req.InstallMonAgent != "no" || option != "register" { - fmt.Printf("[Init monitoring agent] for %+v\n - req.InstallMonAgent: %+v\n\n", mcisTmp.Id, req.InstallMonAgent) - check := CheckDragonflyEndpoint() if check != nil { fmt.Printf("\n\n[Warring] CB-Dragonfly is not available\n\n") @@ -959,6 +955,11 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) reqToMon := &McisCmdReq{} reqToMon.UserName = "cb-user" // this MCIS user name is temporal code. Need to improve. + fmt.Printf("\n===========================\n") + // Sleep for 60 seconds for a safe DF agent installation. + fmt.Printf("\n\n[Info] Sleep for 60 seconds for safe CB-Dragonfly Agent installation.\n") + time.Sleep(60 * time.Second) + fmt.Printf("\n[InstallMonitorAgentToMcis]\n\n") content, err := InstallMonitorAgentToMcis(nsId, mcisId, mcisTmp.SystemLabel, reqToMon) if err != nil { @@ -970,13 +971,6 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) } } - // Configure Cloud Adaptive Network - if true { //mcisTmp.ConfigureCloudAdaptiveNetwork != "no" { - - fmt.Printf("\n[Configure Cloud Adaptive Network] for %+v\n - req.ConfigureCloudAdaptiveNetwork: %+v\n\n", mcisId, "yes") //mcisTmp.ConfigureCloudAdaptiveNetwork) - configureCloudAdaptiveNetwork(nsId, mcisTmp) - } - mcisResult, err := GetMcisInfo(nsId, mcisId) if err != nil { common.CBLog.Error(err) @@ -1183,6 +1177,7 @@ func AddVmToMcis(wg *sync.WaitGroup, nsId string, mcisId string, vmInfoData *TbV // Monitoring Agent Installation Status (init: notInstalled) vmInfoData.MonAgentStatus = "notInstalled" + vmInfoData.NetworkAgentStatus = "notInstalled" // set CreatedTime t := time.Now() From cfad144b8d8b5b16da2b69774339e3c0a8901634 Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Tue, 5 Apr 2022 09:40:57 +0900 Subject: [PATCH 3/4] Read endpoints for the cloud adaptive network from the env - Read the endpoints from the env if not passed as a parameter --- src/core/mcis/network.go | 32 +++++++++++++++++++++++--------- src/core/mcis/provisioning.go | 2 +- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/core/mcis/network.go b/src/core/mcis/network.go index 84ff6f911..a0f37684c 100644 --- a/src/core/mcis/network.go +++ b/src/core/mcis/network.go @@ -16,8 +16,10 @@ package mcis import ( "encoding/json" + "errors" "fmt" "log" + "os" "strings" "sync" @@ -30,8 +32,8 @@ import ( // NetworkReq is a struct for a request to configure Cloud Adaptive Network type NetworkReq struct { - ServiceEndpoint string `json:"serviceEndpoint" example:"localhost:8053" default:"localhost:8053"` - EtcdEndpoints []string `json:"etcdEndpoints" example:"[\"PUBLIC_IP_1:2379\", \"PUBLIC_IP_2:2379\", ...]"` + ServiceEndpoint string `json:"serviceEndpoint" example:"localhost:8053" default:""` + EtcdEndpoints []string `json:"etcdEndpoints" example:"[\"PUBLIC_IP_1:2379\", \"PUBLIC_IP_2:2379\", ...]" default:"[]"` } // ConfigureCloudAdaptiveNetwork configures a cloud adaptive network to VMs in an MCIS @@ -59,11 +61,23 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe return AgentInstallContentWrapper{}, err } - // // Check cb-network endpoints - // networkServiceEndpoint, etcdEndpoints, err := checkCBNetworkEndpoints() - // if err != nil { - // return cladnetSpec, err - // } + // if the parameter is not passed, try to read from the environment variable + if netReq.ServiceEndpoint == "" { + // Get an endpoint of cb-network service + serviceEndpoint := os.Getenv("CB_NETWORK_SERVICE_ENDPOINT") + if serviceEndpoint == "" { + return AgentInstallContentWrapper{}, errors.New("there is no CB_NETWORK_SERVICE_ENDPOINT") + } + } + + // if the parameter is not passed, try to read from the environment variable + if len(netReq.EtcdEndpoints) == 0 { + // Get endpoints of cb-network etcd which should be accessible from the remote + etcdEndpoints := os.Getenv("CB_NETWORK_ETCD_ENDPOINTS") + if etcdEndpoints == "" { + return AgentInstallContentWrapper{}, errors.New("there is no CB_NETWORK_ETCD_ENDPOINTS") + } + } // Get Cloud Adaptive Network cladnetSpec, err := getCloudAdaptiveNetwork(netReq.ServiceEndpoint, mcisId) @@ -160,8 +174,8 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe return contents, nil } -// // checkCBNetworkEndpoints checks endpoints of cb-network service and etcd. -// func checkCBNetworkEndpoints() (string, string, error) { +// // readCBNetworkEndpoints checks endpoints of cb-network service and etcd. +// func readCBNetworkEndpoints() (string, string, error) { // common.CBLog.Debug("Start.........") // // Get an endpoint of cb-network service diff --git a/src/core/mcis/provisioning.go b/src/core/mcis/provisioning.go index 00e824931..e0043b69d 100644 --- a/src/core/mcis/provisioning.go +++ b/src/core/mcis/provisioning.go @@ -168,7 +168,7 @@ type TbMcisInfo struct { InstallMonAgent string `json:"installMonAgent" example:"yes" default:"yes" enums:"yes,no"` // yes or no // ConfigureCloudAdaptiveNetwork is an option to configure Cloud Adaptive Network (CLADNet) ([yes/no] default:yes) - ConfigureCloudAdaptiveNetwork string `json:"configureCloudAdaptiveNetwork" example:"yes" default:"yes" enums:"yes,no"` // yes or no + ConfigureCloudAdaptiveNetwork string `json:"configureCloudAdaptiveNetwork" example:"yes" default:"no" enums:"yes,no"` // yes or no // Label is for describing the mcis in a keyword (any string can be used) Label string `json:"label" example:"User custom label"` From 7c1075ca2059dd8fb81b550c40c83ce35e66941e Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Tue, 5 Apr 2022 15:52:17 +0900 Subject: [PATCH 4/4] Update src/core/mcis/network.go - Update method of endpoints passing or reading - Fix invaild memory access --- conf/setup.env | 3 ++- src/core/mcis/network.go | 42 ++++++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/conf/setup.env b/conf/setup.env index 2c30e2953..b12c0fa66 100644 --- a/conf/setup.env +++ b/conf/setup.env @@ -17,7 +17,8 @@ export API_USERNAME=default export API_PASSWORD=default export CB_NETWORK_SERVICE_ENDPOINT=localhost:8053 -export CB_NETWORK_ETCD_ENDPOINTS='["localhost:2379"]' +# comma separated such as "aaa.aaa.aaa.aaa:2379,bbb.bbb.bbb.bbb:2379,..." +export CB_NETWORK_ETCD_ENDPOINTS="localhost:2379" # Set period for auto control goroutine invocation export AUTOCONTROL_DURATION_MS=10000 diff --git a/src/core/mcis/network.go b/src/core/mcis/network.go index a0f37684c..5879d97f5 100644 --- a/src/core/mcis/network.go +++ b/src/core/mcis/network.go @@ -33,7 +33,7 @@ import ( // NetworkReq is a struct for a request to configure Cloud Adaptive Network type NetworkReq struct { ServiceEndpoint string `json:"serviceEndpoint" example:"localhost:8053" default:""` - EtcdEndpoints []string `json:"etcdEndpoints" example:"[\"PUBLIC_IP_1:2379\", \"PUBLIC_IP_2:2379\", ...]" default:"[]"` + EtcdEndpoints []string `json:"etcdEndpoints" example:"PUBLIC_IP_1:2379,PUBLIC_IP_2:2379,..." default:""` } // ConfigureCloudAdaptiveNetwork configures a cloud adaptive network to VMs in an MCIS @@ -61,26 +61,32 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe return AgentInstallContentWrapper{}, err } + serviceEndpoint := netReq.ServiceEndpoint // if the parameter is not passed, try to read from the environment variable - if netReq.ServiceEndpoint == "" { + if serviceEndpoint == "" { + common.CBLog.Printf("read env for CB_NETWORK_SERVICE_ENDPOINT") // Get an endpoint of cb-network service - serviceEndpoint := os.Getenv("CB_NETWORK_SERVICE_ENDPOINT") + serviceEndpoint = os.Getenv("CB_NETWORK_SERVICE_ENDPOINT") if serviceEndpoint == "" { return AgentInstallContentWrapper{}, errors.New("there is no CB_NETWORK_SERVICE_ENDPOINT") } } + common.CBLog.Printf("Network service endpoint: %+v", serviceEndpoint) + etcdEndpoints := netReq.EtcdEndpoints // if the parameter is not passed, try to read from the environment variable - if len(netReq.EtcdEndpoints) == 0 { + if len(etcdEndpoints) == 0 { + common.CBLog.Printf("read env for CB_NETWORK_ETCD_ENDPOINTS") // Get endpoints of cb-network etcd which should be accessible from the remote - etcdEndpoints := os.Getenv("CB_NETWORK_ETCD_ENDPOINTS") - if etcdEndpoints == "" { + etcdEndpoints = strings.Split(os.Getenv("CB_NETWORK_ETCD_ENDPOINTS"), ",") + if len(etcdEndpoints) == 0 { return AgentInstallContentWrapper{}, errors.New("there is no CB_NETWORK_ETCD_ENDPOINTS") } } + common.CBLog.Printf("etcd endpoints: %+v", etcdEndpoints) // Get Cloud Adaptive Network - cladnetSpec, err := getCloudAdaptiveNetwork(netReq.ServiceEndpoint, mcisId) + cladnetSpec, err := getCloudAdaptiveNetwork(serviceEndpoint, mcisId) if err != nil { common.CBLog.Error(err) return AgentInstallContentWrapper{}, err @@ -97,7 +103,7 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe // Get a propoer address space cladnetDescription := fmt.Sprintf("A cladnet for %s", mcisId) - cladnetSpec, err = createProperCloudAdaptiveNetwork(netReq.ServiceEndpoint, ipNetworksInMCIS, mcisId, cladnetDescription) + cladnetSpec, err = createProperCloudAdaptiveNetwork(serviceEndpoint, ipNetworksInMCIS, mcisId, cladnetDescription) if err != nil { common.CBLog.Printf("could not create a cloud adaptive network: %v\n", err) return AgentInstallContentWrapper{}, err @@ -107,8 +113,9 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe common.CBLog.Printf("Struct: %#v\n", cladnetSpec) // Prepare the installation command - etcdEndpointsJSON, _ := json.Marshal(netReq.EtcdEndpoints) + etcdEndpointsJSON, _ := json.Marshal(etcdEndpoints) command := makeInstallationCommand(string(etcdEndpointsJSON), cladnetSpec.ID) + common.CBLog.Printf("Command: %#v\n", command) // Replace given parameter with the installation cmd mcisCmdReq := McisCmdReq{} @@ -119,11 +126,13 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe // sshCmdResults, err := installCBNetworkAgentToMcis(nsId, mcisId, mcisCmdReq) // Install cb-network agents in parallel - var wg *sync.WaitGroup + var wg sync.WaitGroup chanResults := make(chan SshCmdResult) var sshCmdResults []SshCmdResult + common.CBLog.Printf("VM list: %v\n", vmIdList) + for _, vmId := range vmIdList { wg.Add(1) go func(nsId, mcisId, vmId string, mcisCmdReq McisCmdReq, chanResults chan SshCmdResult) { @@ -131,22 +140,21 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe // Check NetworkAgentStatus vmObject, _ := GetVmObject(nsId, mcisId, vmId) - fmt.Println("NetworkAgentStatus : " + vmObject.NetworkAgentStatus) + common.CBLog.Printf("NetworkAgentStatus: %+v\n" + vmObject.NetworkAgentStatus) // Skip if in installing or installed status) if vmObject.NetworkAgentStatus != "installed" && vmObject.NetworkAgentStatus != "installing" { - vmObj, _ := GetVmObject(nsId, mcisId, vmId) - vmObj.NetworkAgentStatus = "installing" + vmObject.NetworkAgentStatus = "installing" - SshCmdResult, err := installCBNetworkAgentToVM(nsId, mcisId, vmId, mcisCmdReq) + sshCmdResult, err := installCBNetworkAgentToVM(nsId, mcisId, vmId, mcisCmdReq) if err != nil { vmObject.NetworkAgentStatus = "installed" } else { vmObject.NetworkAgentStatus = "failed" } - chanResults <- SshCmdResult + chanResults <- sshCmdResult } }(nsId, mcisId, vmId, mcisCmdReq, chanResults) @@ -332,8 +340,8 @@ func makeInstallationCommand(etcdEndpoints, cladnetId string) string { // SSH command to install cb-network agents placeHolderCommand := `wget https://raw.githubusercontent.com/cloud-barista/cb-larva/develop/poc-cb-net/scripts/1.deploy-cb-network-agent.sh -O ~/1.deploy-cb-network-agent.sh; chmod +x ~/1.deploy-cb-network-agent.sh; source ~/1.deploy-cb-network-agent.sh '%s' %s` - additionalEncodedString := strings.Replace(etcdEndpoints, "\"", "\\\"", -1) - command := fmt.Sprintf(placeHolderCommand, additionalEncodedString, cladnetId) + // additionalEncodedString := strings.Replace(etcdEndpoints, "\"", "\\\"", -1) + command := fmt.Sprintf(placeHolderCommand, etcdEndpoints, cladnetId) return command }