github.com/vmware/govmomi@v0.43.0/simulator/host_firewall_system.go (about) 1 /* 2 Copyright (c) 2017 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package simulator 18 19 import ( 20 "github.com/vmware/govmomi/simulator/esx" 21 "github.com/vmware/govmomi/vim25/methods" 22 "github.com/vmware/govmomi/vim25/mo" 23 "github.com/vmware/govmomi/vim25/soap" 24 "github.com/vmware/govmomi/vim25/types" 25 ) 26 27 type HostFirewallSystem struct { 28 mo.HostFirewallSystem 29 } 30 31 func NewHostFirewallSystem(_ *mo.HostSystem) *HostFirewallSystem { 32 info := esx.HostFirewallInfo 33 34 return &HostFirewallSystem{ 35 HostFirewallSystem: mo.HostFirewallSystem{ 36 FirewallInfo: &info, 37 }, 38 } 39 } 40 41 func DisableRuleset(info *types.HostFirewallInfo, id string) bool { 42 for i := range info.Ruleset { 43 if info.Ruleset[i].Key == id { 44 info.Ruleset[i].Enabled = false 45 return true 46 } 47 } 48 49 return false 50 } 51 52 func (s *HostFirewallSystem) DisableRuleset(req *types.DisableRuleset) soap.HasFault { 53 body := &methods.DisableRulesetBody{} 54 55 if DisableRuleset(s.HostFirewallSystem.FirewallInfo, req.Id) { 56 body.Res = new(types.DisableRulesetResponse) 57 return body 58 } 59 60 body.Fault_ = Fault("", &types.NotFound{}) 61 62 return body 63 } 64 65 func EnableRuleset(info *types.HostFirewallInfo, id string) bool { 66 for i := range info.Ruleset { 67 if info.Ruleset[i].Key == id { 68 info.Ruleset[i].Enabled = true 69 return true 70 } 71 } 72 73 return false 74 } 75 76 func (s *HostFirewallSystem) EnableRuleset(req *types.EnableRuleset) soap.HasFault { 77 body := &methods.EnableRulesetBody{} 78 79 if EnableRuleset(s.HostFirewallSystem.FirewallInfo, req.Id) { 80 body.Res = new(types.EnableRulesetResponse) 81 return body 82 } 83 84 body.Fault_ = Fault("", &types.NotFound{}) 85 86 return body 87 }