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

fix(azure): secgroup delete #515

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions pkg/multicloud/aliyun/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,6 @@ func (self *SVpc) GetIRouteTableById(routeTableId string) (cloudprovider.ICloudR
}

func (self *SVpc) Delete() error {
secgroups, err := self.region.GetSecurityGroups(self.VpcId, "", nil)
if err != nil {
return errors.Wrapf(err, "GetSecurityGroups")
}
for i := 0; i < len(secgroups); i += 1 {
err := self.region.DeleteSecurityGroup(secgroups[i].SecurityGroupId)
if err != nil {
return errors.Wrapf(err, "DeleteSecurityGroup %s", secgroups[i].SecurityGroupId)
}
}
return self.region.DeleteVpc(self.VpcId)
}

Expand Down
14 changes: 0 additions & 14 deletions pkg/multicloud/apsara/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"time"

"yunion.io/x/jsonutils"
"yunion.io/x/log"

"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/cloudmux/pkg/multicloud"
Expand Down Expand Up @@ -261,19 +260,6 @@ func (self *SVpc) GetIRouteTableById(routeTableId string) (cloudprovider.ICloudR
}

func (self *SVpc) Delete() error {
err := self.fetchSecurityGroups()
if err != nil {
log.Errorf("fetchSecurityGroup for VPC delete fail %s", err)
return err
}
for i := 0; i < len(self.secgroups); i += 1 {
secgroup := self.secgroups[i].(*SSecurityGroup)
err := self.region.DeleteSecurityGroup(secgroup.SecurityGroupId)
if err != nil {
log.Errorf("deleteSecurityGroup for VPC delete fail %s", err)
return err
}
}
return self.region.DeleteVpc(self.VpcId)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/multicloud/azure/instancenic.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type InterfaceIPConfiguration struct {
}

type InterfacePropertiesFormat struct {
NetworkSecurityGroup SSecurityGroup `json:"networkSecurityGroup,omitempty"`
NetworkSecurityGroup *SSecurityGroup `json:"networkSecurityGroup,omitempty"`
IPConfigurations []InterfaceIPConfiguration `json:"ipConfigurations,omitempty"`
MacAddress string `json:"macAddress,omitempty"`
Primary bool `json:"primary,omitempty"`
Expand Down Expand Up @@ -101,7 +101,7 @@ func (self *SInstanceNic) InClassicNetwork() bool {
func (self *SInstanceNic) updateSecurityGroup(secgroupId string) error {
region := self.instance.host.zone.region
if len(secgroupId) > 0 {
self.Properties.NetworkSecurityGroup = SSecurityGroup{ID: secgroupId}
self.Properties.NetworkSecurityGroup = &SSecurityGroup{ID: secgroupId}
}
return region.update(jsonutils.Marshal(self), nil)
}
Expand Down
33 changes: 24 additions & 9 deletions pkg/multicloud/azure/securitygroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type SecurityGroupPropertiesFormat struct {
DefaultSecurityRules []SecurityRules `json:"defaultSecurityRules,omitempty"`
NetworkInterfaces *[]Interface `json:"networkInterfaces,omitempty"`
Subnets *[]SNetwork `json:"subnets,omitempty"`
ProvisioningState string //Possible values are: 'Updating', 'Deleting', and 'Failed'
}
type SSecurityGroup struct {
multicloud.SSecurityGroup
Expand Down Expand Up @@ -131,7 +130,7 @@ func (region *SRegion) AttachSecurityToInterfaces(secgroupId string, nicIds []st
if err != nil {
return err
}
nic.Properties.NetworkSecurityGroup = SSecurityGroup{ID: secgroupId}
nic.Properties.NetworkSecurityGroup = &SSecurityGroup{ID: secgroupId}
if err := region.update(jsonutils.Marshal(nic), nil); err != nil {
return err
}
Expand Down Expand Up @@ -165,14 +164,30 @@ func (self *SSecurityGroup) CreateRule(opts *cloudprovider.SecurityGroupRuleCrea
}

func (self *SSecurityGroup) Delete() error {
if self.Properties != nil && self.Properties.NetworkInterfaces != nil {
for _, nic := range *self.Properties.NetworkInterfaces {
nic, err := self.region.GetNetworkInterface(nic.ID)
if err != nil {
return err
if self.Properties != nil {
if self.Properties.NetworkInterfaces != nil {
for _, nic := range *self.Properties.NetworkInterfaces {
nic, err := self.region.GetNetworkInterface(nic.ID)
if err != nil {
return errors.Wrapf(err, "get nic %s", nic.ID)
}
nic.Properties.NetworkSecurityGroup = nil
err = self.region.update(jsonutils.Marshal(nic), nil)
if err != nil {
return errors.Wrapf(err, "update nic")
}
}
if err := self.region.update(jsonutils.Marshal(nic), nil); err != nil {
return err
}
if self.Properties.Subnets != nil {
for _, _net := range *self.Properties.Subnets {
net, err := self.region.GetNetwork(_net.ID)
if err != nil {
return errors.Wrapf(err, "get network %s", _net.ID)
}
err = self.region.update(jsonutils.Marshal(net), nil)
if err != nil {
return errors.Wrapf(err, "update network")
}
}
}
}
Expand Down
Loading