securitygroup.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package ecloud
  15. import (
  16. "yunion.io/x/jsonutils"
  17. api "yunion.io/x/cloudmux/pkg/apis/compute"
  18. "yunion.io/x/cloudmux/pkg/cloudprovider"
  19. "yunion.io/x/cloudmux/pkg/multicloud"
  20. )
  21. // SSecurityGroup 与 ecloudsdkvpc ListSecGroupResponseContent 字段对应
  22. type SSecurityGroup struct {
  23. multicloud.SSecurityGroup
  24. EcloudTags
  25. region *SRegion
  26. Id string `json:"id"`
  27. Name string `json:"name"`
  28. Description string `json:"description"`
  29. Region string `json:"region"`
  30. Type string `json:"type"`
  31. CreatedTime string `json:"createdTime"`
  32. Defaulted *bool `json:"defaulted,omitempty"`
  33. Stateful *bool `json:"stateful,omitempty"`
  34. Scale string `json:"scale,omitempty"`
  35. VpoolId *string `json:"vpoolId,omitempty"`
  36. Vaz *string `json:"vaz,omitempty"`
  37. }
  38. func (sg *SSecurityGroup) GetId() string {
  39. return sg.Id
  40. }
  41. func (sg *SSecurityGroup) GetName() string {
  42. return sg.Name
  43. }
  44. func (sg *SSecurityGroup) GetGlobalId() string {
  45. return sg.Id
  46. }
  47. func (sg *SSecurityGroup) GetDescription() string {
  48. return sg.Description
  49. }
  50. func (sg *SSecurityGroup) GetStatus() string {
  51. return api.SECGROUP_STATUS_READY
  52. }
  53. func (sg *SSecurityGroup) GetVpcId() string {
  54. // 移动云安全组为 region 维度,非 VPC 维度
  55. return ""
  56. }
  57. func (sg *SSecurityGroup) Refresh() error {
  58. latest, err := sg.region.GetSecurityGroup(sg.Id)
  59. if err != nil {
  60. return err
  61. }
  62. return jsonutils.Update(sg, latest)
  63. }
  64. func (sg *SSecurityGroup) GetRules() ([]cloudprovider.ISecurityGroupRule, error) {
  65. rules, err := sg.region.GetSecurityGroupRules(sg.Id)
  66. if err != nil {
  67. return nil, err
  68. }
  69. ret := make([]cloudprovider.ISecurityGroupRule, len(rules))
  70. for i := range rules {
  71. ret[i] = &rules[i]
  72. }
  73. return ret, nil
  74. }
  75. func (sg *SSecurityGroup) CreateRule(opts *cloudprovider.SecurityGroupRuleCreateOptions) (cloudprovider.ISecurityGroupRule, error) {
  76. rule, err := sg.region.CreateSecurityGroupRule(sg.Id, opts)
  77. if err != nil {
  78. return nil, err
  79. }
  80. return rule, nil
  81. }
  82. func (sg *SSecurityGroup) GetReferences() ([]cloudprovider.SecurityGroupReference, error) {
  83. return nil, nil
  84. }
  85. func (sg *SSecurityGroup) Delete() error {
  86. return sg.region.DeleteSecurityGroup(sg.Id)
  87. }