func (s *PortSetSuite) checkPortSet(c *gc.C, ports network.PortSet, protocol string, expected ...int) { var sexpected []string for _, port := range expected { sexpected = append(sexpected, strconv.Itoa(port)) } values := ports.PortStrings(protocol) c.Check(values, jc.SameContents, sexpected) }
// firewallSpec expands a port range set in to compute.FirewallAllowed // and returns a compute.Firewall for the provided name. func firewallSpec(name string, ps network.PortSet) *compute.Firewall { firewall := compute.Firewall{ // Allowed is set below. // Description is not set. Name: name, // Network: (defaults to global) // SourceTags is not set. TargetTags: []string{name}, SourceRanges: []string{"0.0.0.0/0"}, } for _, protocol := range ps.Protocols() { allowed := compute.FirewallAllowed{ IPProtocol: protocol, Ports: ps.PortStrings(protocol), } firewall.Allowed = append(firewall.Allowed, &allowed) } return &firewall }