// formatFirewallRulesTabular returns a tabular summary of firewall rules.
355105
func formatFirewallRulesTabular(writer io.Writer, rules firewallRules) {
	tw := output.TabWriter(writer)
	w := output.Wrapper{tw}

	sort.Sort(rules)

	w.Println("Service", "Whitelist subnets")
	for _, rule := range rules {
		w.Println(rule.KnownService, strings.Join(rule.WhitelistCIDRS, ","))
	}
	tw.Flush()
}
1361812
func (s *VPCRouterSetting) RemoveFirewallRuleSend(ifIndex int, isAllow bool, protocol string, sourceNetwork string, sourcePort string, destNetwork string, destPort string) {
	action := "deny"
	if isAllow {
		action = "allow"
	}

	rule := &VPCRouterFirewallRule{
		Action:             action,
		Protocol:           protocol,
		SourceNetwork:      sourceNetwork,
		SourcePort:         sourcePort,
		DestinationNetwork: destNetwork,
		DestinationPort:    destPort,
	}

	s.removeFirewallRule(ifIndex, "send", rule)
}
604011
func (c *CloudAPI) UpdateFirewallRule(fwRuleID, rule string, enabled bool) (*cloudapi.FirewallRule, error) {
	if err := c.ProcessFunctionHook(c, fwRuleID, rule, enabled); err != nil {
		return nil, err
	}

	for _, r := range c.firewallRules {
		if strings.EqualFold(r.Id, fwRuleID) {
			r.Rule = rule
			r.Enabled = enabled
			return r, nil
		}
	}

	return nil, fmt.Errorf("Firewall rule %s not found", fwRuleID)
}
863198
func FormatTabularBlockedModels(writer io.Writer, value interface{}) error {
	models, ok := value.([]modelBlockInfo)
	if !ok {
		return errors.Errorf("expected value of type %T, got %T", models, value)
	}

	tw := output.TabWriter(writer)
	w := output.Wrapper{tw}
	w.Println("Name", "Model UUID", "Owner", "Disabled commands")
	for _, model := range models {
		w.Println(model.Name, model.UUID, model.Owner, strings.Join(model.CommandSets, ", "))
	}
	tw.Flush()
	return nil
}
618359
func (s *VPCRouterSetting) AddFirewallRuleSend(ifIndex int, isAllow bool, protocol string,
	sourceNetwork string, sourcePort string, destNetwork string, destPort string,
	logging bool, description string) (int, *VPCRouterFirewallRule) {
	action := "deny"
	if isAllow {
		action = "allow"
	}
	strLogging := "False"
	if logging {
		strLogging = "True"
	}

	rule := &VPCRouterFirewallRule{
		Action:             action,
		Protocol:           protocol,
		SourceNetwork:      sourceNetwork,
		SourcePort:         sourcePort,
		DestinationNetwork: destNetwork,
		DestinationPort:    destPort,
		Logging:            strLogging,
		Description:        description,
	}

	i := s.addFirewallRule(ifIndex, "send", rule)
	return i, rule
}
72725
func FormatTabular(writer io.Writer, forceColor bool, value interface{}) error {
	fs, valueConverted := value.(formattedStatus)
	if !valueConverted {
		return errors.Errorf("expected value of type %T, got %T", fs, value)
	}

	// To format things into columns.
	tw := output.TabWriter(writer)
	if forceColor {
		tw.SetColorCapable(forceColor)
	}

	cloudRegion := fs.Model.Cloud
	if fs.Model.CloudRegion != "" {
		cloudRegion += "/" + fs.Model.CloudRegion
	}

	// Default table output
	header := []interface{}{"Model", "Controller", "Cloud/Region", "Version"}
	values := []interface{}{fs.Model.Name, fs.Model.Controller, cloudRegion, fs.Model.Version}

	// Optional table output if values exist
	message := getModelMessage(fs.Model)
	if fs.Model.SLA != "" {
		header = append(header, "SLA")
		values = append(values, fs.Model.SLA)
	}
	if cs := fs.Controller; cs != nil && cs.Timestamp != "" {
		header = append(header, "Timestamp")
		values = append(values, cs.Timestamp)
	}
	if message != "" {
		header = append(header, "Notes")
		values = append(values, message)
	}

	// The first set of headers don't use outputHeaders because it adds the blank line.
	w := startSection(tw, true, header...)
	w.Println(values...)

	if len(fs.RemoteApplications) > 0 {
		printRemoteApplications(tw, fs.RemoteApplications)
	}

	if len(fs.Applications) > 0 {
		printApplications(tw, fs)
	}

	if fs.Model.Type != caasModelType && len(fs.Machines) > 0 {
		printMachines(tw, false, fs.Machines)
	}

	if err := printOffers(tw, fs.Offers); err != nil {
		w.Println(err.Error())
	}

	if len(fs.Relations) > 0 {
		printRelations(tw, fs.Relations)
	}

	if fs.Storage != nil {
		storage.FormatStorageListForStatusTabular(tw, *fs.Storage)
	}

	endSection(tw)
	return nil
}
1308477
func (d *clusterDiscoveryGCE) listFirewallRules() ([]*resources.Resource, error) {
	c := d.gceCloud

	var resourceTrackers []*resources.Resource

	ctx := context.Background()

	err := c.Compute().Firewalls.List(c.Project()).Pages(ctx, func(page *compute.FirewallList) error {
		for _, fr := range page.Items {
			if !d.matchesClusterNameMultipart(fr.Name, maxPrefixTokens) {
				continue
			}

			foundMatchingTarget := false
			tagPrefix := gce.SafeClusterName(d.clusterName) + "-"
			for _, target := range fr.TargetTags {
				if strings.HasPrefix(target, tagPrefix) {
					foundMatchingTarget = true
				}
			}
			if !foundMatchingTarget {
				break
			}

			resourceTracker := &resources.Resource{
				Name:    fr.Name,
				ID:      fr.Name,
				Type:    typeFirewallRule,
				Deleter: deleteFirewallRule,
				Obj:     fr,
			}

			glog.V(4).Infof("Found resource: %s", fr.SelfLink)
			resourceTrackers = append(resourceTrackers, resourceTracker)
		}
		return nil
	})
	if err != nil {
		return nil, fmt.Errorf("error listing FirewallRules: %v", err)
	}

	return resourceTrackers, nil
}
1374453
func NewSetFirewallRuleCommand() cmd.Command {
	cmd := &setFirewallRuleCommand{}
	cmd.newAPIFunc = func() (SetFirewallRuleAPI, error) {
		root, err := cmd.NewAPIRoot()
		if err != nil {
			return nil, errors.Trace(err)
		}
		return firewallrules.NewClient(root), nil

	}
	return modelcmd.Wrap(cmd)
}
983915
func (o *L2Domain) VirtualFirewallRules(info *bambou.FetchingInfo) (VirtualFirewallRulesList, *bambou.Error) {

	var list VirtualFirewallRulesList
	err := bambou.CurrentSession().FetchChildren(o, VirtualFirewallRuleIdentity, &list, info)
	return list, err
}
1245348
func (c *Client) DeleteFirewallRule(ruleNumber int, groupID string) error {
	values := url.Values{
		"FIREWALLGROUPID": {groupID},
		"rulenumber":      {fmt.Sprintf("%v", ruleNumber)},
	}

	if err := c.post(`firewall/rule_delete`, values, nil); err != nil {
		return err
	}
	return nil
}
296235
func (l HostFirewallRulesetList) ByRule(rule types.HostFirewallRule) HostFirewallRulesetList {
	var matches HostFirewallRulesetList

	for _, rs := range l {
		for _, r := range rs.Rule {
			if r.PortType != rule.PortType ||
				r.Protocol != rule.Protocol ||
				r.Direction != rule.Direction {
				continue
			}

			if r.EndPort == 0 && rule.Port == r.Port ||
				rule.Port >= r.Port && rule.Port <= r.EndPort {
				matches = append(matches, rs)
				break
			}
		}
	}

	return matches
}
884272
func formatTabular(writer io.Writer, value interface{}) error {
	b, ok := value.(*wireformat.ListWalletsResponse)
	if !ok {
		return errors.Errorf("expected value of type %T, got %T", b, value)
	}
	sort.Sort(b.Wallets)

	table := uitable.New()
	table.MaxColWidth = 50
	table.Wrap = true
	for _, col := range []int{1, 2, 3, 4} {
		table.RightAlign(col)
	}

	table.AddRow("Wallet", "Monthly", "Budgeted", "Available", "Spent")
	for _, walletEntry := range b.Wallets {
		suffix := ""
		if walletEntry.Default {
			suffix = "*"
		}
		table.AddRow(walletEntry.Wallet+suffix, walletEntry.Limit, walletEntry.Budgeted, walletEntry.Available, walletEntry.Consumed)
	}
	table.AddRow("Total", b.Total.Limit, b.Total.Budgeted, b.Total.Available, b.Total.Consumed)
	table.AddRow("", "", "", "", "")
	table.AddRow("Credit limit:", b.Credit, "", "", "")
	fmt.Fprint(writer, table)
	return nil
}
1141495
func formatFoundEndpointsTabular(writer io.Writer, all map[string]ApplicationOfferResult) error {
	tw := output.TabWriter(writer)
	w := output.Wrapper{tw}
	w.Println("Store", "URL", "Access", "Interfaces")

	for urlStr, one := range all {
		url, err := crossmodel.ParseOfferURL(urlStr)
		if err != nil {
			return err
		}
		store := url.Source
		url.Source = ""

		interfaces := []string{}
		for name, ep := range one.Endpoints {
			interfaces = append(interfaces, fmt.Sprintf("%s:%s", ep.Interface, name))
		}
		sort.Strings(interfaces)
		w.Println(store, url.String(), one.Access, strings.Join(interfaces, ", "))
	}
	tw.Flush()

	return nil
}
1266128
func formatPoolListTabular(writer io.Writer, value interface{}) error {
	pools, ok := value.(map[string]PoolInfo)
	if !ok {
		return errors.Errorf("expected value of type %T, got %T", pools, value)
	}
	formatPoolsTabular(writer, pools)
	return nil
}
1058848
func (s *FirewallService) ListFirewallRules(p *ListFirewallRulesParams) (*ListFirewallRulesResponse, error) {
	resp, err := s.cs.newRequest("listFirewallRules", p.toURLValues())
	if err != nil {
		return nil, err
	}

	resp, err = convertFirewallServiceResponse(resp)
	if err != nil {
		return nil, err
	}

	var r ListFirewallRulesResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
1354527
func (c *legacyNovaFirewaller) IngressRules(ctx context.ProviderCallContext) ([]network.IngressRule, error) {
	return c.ingressRules(ctx, c.ingressRulesInGroup)
}
246427
func (c *CloudAPI) CreateFirewallRule(rule string, enabled bool) (*cloudapi.FirewallRule, error) {
	if err := c.ProcessFunctionHook(c, rule, enabled); err != nil {
		return nil, err
	}

	fwRuleID, err := localservices.NewUUID()
	if err != nil {
		return nil, fmt.Errorf("Error creating firewall rule: %q", err)
	}

	fwRule := &cloudapi.FirewallRule{Id: fwRuleID, Rule: rule, Enabled: enabled}
	c.firewallRules = append(c.firewallRules, fwRule)

	return fwRule, nil
}