Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subnet mgmt feature & REST APIs #878

Merged

Conversation

jihoon-seo
Copy link
Member

  • vNet 테스트 스크립트에서, subnet 테스트를 위해 다음과 같이 변경했습니다. 주의가 필요합니다.
			"cidrBlock": "192.168.${CIDRDiff}.0/24",
			"subnetInfoList": [ {
				"Name": "${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX}",
-				"IPv4_CIDR": "192.168.${CIDRDiff}.0/24"
+				"IPv4_CIDR": "192.168.${CIDRDiff}.128/28"
  • TbVNetReq struct에서 subnet 정보를 다루기 위해 SpiderSubnetReqInfo struct를 사용하고 있었는데,
    TbSubnetReq struct를 새로 정의하고 이를 사용하도록 변경했습니다.
    (API 변경을 최소화하도록, 두 struct의 field는 거의 동일합니다.)
  • TbVNetInfo struct에서 subnet 정보를 다루기 위해 SpiderSubnetInfo struct를 사용하고 있었는데,
    TbSubnetInfo struct를 새로 정의하고 이를 사용하도록 변경했습니다.
    (API 변경을 최소화하도록, 두 struct의 field는 거의 동일합니다.)
  • Added REST APIs
    • g.POST("/:nsId/resources/vNet/:vNetId/subnet", rest_mcir.RestPostSubnet)
    • g.DELETE("/:nsId/resources/vNet/:parentResourceId/subnet/:childResourceId", rest_mcir.RestDelChildResource)
  • Added REST API functions
    • func RestPostSubnet(c echo.Context) error
    • func RestDelChildResource(c echo.Context) error
    • func RestDelSubnet(c echo.Context) error (dummy function to generate Swagger doc entries)
  • Added some functions
    • func CreateSubnet(nsId string, vNetId string, req TbSubnetReq, objectOnly bool) (TbVNetInfo, error)
    • func DelChildResource(nsId string, resourceType string, parentResourceId string, resourceId string, forceFlag string) error
    • func GenChildResourceKey(nsId string, resourceType string, parentResourceId string, resourceId string) string
    • func CheckChildResource(nsId string, resourceType string, parentResourceId string, resourceId string) (bool, error)

[Test outputs]

❯ ./list-vNet.sh       
####################################################################
## 3. VPC: List
####################################################################
{
  "vNet": null
}

❯ ./create-vNet.sh -n jhseo -c aws -r 1
####################################################################
## 3. vNet: Create
####################################################################


- Create vNet in aws-ap-se-1
{
  "id": "aws-ap-se-1-jhseo",
  "name": "aws-ap-se-1-jhseo",
  "connectionName": "aws-ap-se-1",
  "cidrBlock": "192.168.5.0/24",
  "subnetInfoList": [
    {
      "Id": "aws-ap-se-1-jhseo",
      "Name": "aws-ap-se-1-jhseo",
      "IPv4_CIDR": "192.168.5.128/28",
      "KeyValueList": [
        {
          "Key": "VpcId",
          "Value": "vpc-034af1bb3b6a20477"
        },
        {
          "Key": "MapPublicIpOnLaunch",
          "Value": "false"
        },
        {
          "Key": "AvailableIpAddressCount",
          "Value": "11"
        },
        {
          "Key": "AvailabilityZone",
          "Value": "ap-southeast-1a"
        },
        {
          "Key": "Status",
          "Value": "available"
        }
      ],
      "Description": ""
    }
  ],
  "description": "",
  "cspVNetId": "vpc-034af1bb3b6a20477",
  "cspVNetName": "aws-ap-se-1-jhseo",
  "status": "",
  "keyValueList": null,
  "associatedObjectList": [],
  "isAutoGenerated": false
}
❯ ./list-object.sh
...
    "/ns/tb01",
    "/ns/tb01/resources/vNet/aws-ap-se-1-jhseo",
    "/ns/tb01/resources/vNet/aws-ap-se-1-jhseo/subnet/aws-ap-se-1-jhseo"
  ]
}

❯ ./add-subnet.sh -n jhseo -c aws -r 1 
####################################################################
## 3. subnet: Create
####################################################################


- Create subnet in aws-ap-se-1
{
  "id": "aws-ap-se-1-jhseo",
  "name": "aws-ap-se-1-jhseo",
  "connectionName": "aws-ap-se-1",
  "cidrBlock": "192.168.5.0/24",
  "subnetInfoList": [
    {
      "Id": "aws-ap-se-1-jhseo",
      "Name": "aws-ap-se-1-jhseo",
      "IPv4_CIDR": "192.168.5.128/28",
      "KeyValueList": [
        {
          "Key": "VpcId",
          "Value": "vpc-034af1bb3b6a20477"
        },
        {
          "Key": "MapPublicIpOnLaunch",
          "Value": "false"
        },
        {
          "Key": "AvailableIpAddressCount",
          "Value": "11"
        },
        {
          "Key": "AvailabilityZone",
          "Value": "ap-southeast-1a"
        },
        {
          "Key": "Status",
          "Value": "available"
        }
      ],
      "Description": ""
    },
    {
      "Id": "aws-ap-se-1-jhseo-5",
      "Name": "aws-ap-se-1-jhseo-5",
      "IPv4_CIDR": "192.168.5.64/28",
      "KeyValueList": null,
      "Description": ""
    }
  ],
  "description": "",
  "cspVNetId": "vpc-034af1bb3b6a20477",
  "cspVNetName": "aws-ap-se-1-jhseo",
  "status": "",
  "keyValueList": null,
  "associatedObjectList": [],
  "isAutoGenerated": false
}
❯ ./list-object.sh
...
    "/ns/tb01",
    "/ns/tb01/resources/vNet/aws-ap-se-1-jhseo",
    "/ns/tb01/resources/vNet/aws-ap-se-1-jhseo/subnet/aws-ap-se-1-jhseo",
    "/ns/tb01/resources/vNet/aws-ap-se-1-jhseo/subnet/aws-ap-se-1-jhseo-5"
  ]
}

❯ ./remove-subnet.sh -n jhseo -c aws -r 1
####################################################################
## 3. subnet: Remove
####################################################################


- Remove subnet in aws-ap-se-1
{
  "message": "The subnet aws-ap-se-1-jhseo-5 has been deleted"
}
❯ ./list-vNet.sh                         
####################################################################
## 3. VPC: List
####################################################################
{
  "vNet": [
    {
      "id": "aws-ap-se-1-jhseo",
      "name": "aws-ap-se-1-jhseo",
      "connectionName": "aws-ap-se-1",
      "cidrBlock": "192.168.5.0/24",
      "subnetInfoList": [
        {
          "Id": "aws-ap-se-1-jhseo",
          "Name": "aws-ap-se-1-jhseo",
          "IPv4_CIDR": "192.168.5.128/28",
          "KeyValueList": [
            {
              "Key": "VpcId",
              "Value": "vpc-034af1bb3b6a20477"
            },
            {
              "Key": "MapPublicIpOnLaunch",
              "Value": "false"
            },
            {
              "Key": "AvailableIpAddressCount",
              "Value": "11"
            },
            {
              "Key": "AvailabilityZone",
              "Value": "ap-southeast-1a"
            },
            {
              "Key": "Status",
              "Value": "available"
            }
          ],
          "Description": ""
        }
      ],
      "description": "",
      "cspVNetId": "vpc-034af1bb3b6a20477",
      "cspVNetName": "aws-ap-se-1-jhseo",
      "status": "",
      "keyValueList": null,
      "associatedObjectList": [],
      "isAutoGenerated": false
    }
  ]
}
❯ ./list-object.sh
...
    "/ns/tb01",
    "/ns/tb01/resources/vNet/aws-ap-se-1-jhseo",
    "/ns/tb01/resources/vNet/aws-ap-se-1-jhseo/subnet/aws-ap-se-1-jhseo"
  ]
}

❯ ./delete-vNet.sh -n jhseo -c aws -r 1
####################################################################
## 3. vNet: Delete
####################################################################


- Delete vNet in aws-ap-se-1
{
  "message": "The vNet aws-ap-se-1-jhseo has been deleted"
}
❯ ./list-vNet.sh                       
####################################################################
## 3. VPC: List
####################################################################
{
  "vNet": null
}
❯ ./list-object.sh
...
    "/ns/tb01"
  ]
}

[For the record]

To replace CBStore.Put(string(key), string(val)) -> CBStore.Put(key, string(val)) :

find . \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i 's/CBStore.Put(string(\(.*\)),/CBStore.Put(\1,/'

To replace common.CBStore.Get(string(Key)) -> common.CBStore.Get(Key) :

find . \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i 's/CBStore.Get(string(\(.*\)))/CBStore.Get(\1)/'

@jihoon-seo jihoon-seo added the enhancement New feature or request label Oct 20, 2021
@jihoon-seo jihoon-seo requested a review from seokho-son October 20, 2021 09:29
@jihoon-seo jihoon-seo force-pushed the 211019_Update_vNet_mgmt_feature branch from c93585c to 0b7579f Compare October 21, 2021 01:35
@jihoon-seo
Copy link
Member Author

jihoon-seo commented Oct 21, 2021

I resolved conflicts and rebased. 😊

@jihoon-seo jihoon-seo linked an issue Oct 21, 2021 that may be closed by this pull request
@seokho-son
Copy link
Member

@jihoon-seo subnet의 사용 패턴은 어떻게 되는지 질문 드립니다.. ^^

  • vNet 을 삭제하면, 관련 subnet도 모두 삭제 되나요? (CB-TB 오브젝트 및 CSP 자원)
  • vNet에 1개의 subnet이 있는 경우에도 subnet 삭제가 가능한가요?

@jihoon-seo
Copy link
Member Author

@seokho-son

vNet 을 삭제하면, 관련 subnet도 모두 삭제 되나요? (CB-TB 오브젝트 및 CSP 자원)

→ 네 맞습니다~~

  • CSP 자원: (TB → SP → CSP) CSP의 vNet을 지우면 하위 subnet 도 함께 삭제되는 것으로 보입니다. 😊
  • CB-TB 오브젝트: 위의 이유로, TB 에서는 vNet 삭제 시 하위 subnet 삭제를 SP에 개별적으로 요청하지는 않아도 되고
    TB subnet 오브젝트만 삭제하면 되므로,
    DelResource 함수에서 vNet 삭제 시 하위 subnet 오브젝트를 삭제합니다. (CBStore.Delete())

vNet에 1개의 subnet이 있는 경우에도 subnet 삭제가 가능한가요?

❯ ./list-vNet.sh                       
####################################################################
## 3. VPC: List
####################################################################
{
  "vNet": [
    {
      "id": "aws-ap-se-1-jhseo",
      "name": "aws-ap-se-1-jhseo",
      "connectionName": "aws-ap-se-1",
      "cidrBlock": "192.168.5.0/24",
      "subnetInfoList": [
        {
          "Id": "aws-ap-se-1-jhseo",
          "Name": "aws-ap-se-1-jhseo",
          "IPv4_CIDR": "192.168.5.128/28",
          "KeyValueList": [
            {
              "Key": "VpcId",
              "Value": "vpc-0fe1654d166babc42"
            },
            {
              "Key": "MapPublicIpOnLaunch",
              "Value": "false"
            },
            {
              "Key": "AvailableIpAddressCount",
              "Value": "11"
            },
            {
              "Key": "AvailabilityZone",
              "Value": "ap-southeast-1a"
            },
            {
              "Key": "Status",
              "Value": "available"
            }
          ],
          "Description": ""
        }
      ],
      "description": "",
      "cspVNetId": "vpc-0fe1654d166babc42",
      "cspVNetName": "aws-ap-se-1-jhseo",
      "status": "",
      "keyValueList": null,
      "associatedObjectList": [],
      "isAutoGenerated": false
    }
  ]
}
❯ ./remove-subnet.sh -n jhseo -c aws -r 1 
####################################################################
## 3. subnet: Remove
####################################################################


- Remove subnet in aws-ap-se-1
{
  "message": "The subnet aws-ap-se-1-jhseo has been deleted"
}
❯ ./list-vNet.sh                         
####################################################################
## 3. VPC: List
####################################################################
{
  "vNet": [
    {
      "id": "aws-ap-se-1-jhseo",
      "name": "aws-ap-se-1-jhseo",
      "connectionName": "aws-ap-se-1",
      "cidrBlock": "192.168.5.0/24",
      "subnetInfoList": [],
      "description": "",
      "cspVNetId": "vpc-0fe1654d166babc42",
      "cspVNetName": "aws-ap-se-1-jhseo",
      "status": "",
      "keyValueList": null,
      "associatedObjectList": [],
      "isAutoGenerated": false
    }
  ]
}
❯ ./list-object.sh
...
    "/ns/tb01",
    "/ns/tb01/resources/vNet/aws-ap-se-1-jhseo"
  ]
}

Subnet 삭제가 되었습니다. 😊
+ AWS 콘솔, SP AdminWeb 에서도
vNet은 있고 subnet은 삭제된 것을 확인했습니다. 😊

@seokho-son
Copy link
Member

/lgtm

@github-actions github-actions bot added the lgtm This PR is acceptable by at least one reviewer label Oct 21, 2021
@seokho-son seokho-son merged commit cc46a1d into cloud-barista:main Oct 21, 2021
@jihoon-seo jihoon-seo deleted the 211019_Update_vNet_mgmt_feature branch October 21, 2021 08:48
@jihoon-seo jihoon-seo added the hacktoberfest-accepted hacktoberfest-accepted label Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest-accepted hacktoberfest-accepted lgtm This PR is acceptable by at least one reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TODO: Add subnet mgmt features
2 participants