Skip to content

Commit

Permalink
Openstack port resources derived from network
Browse files Browse the repository at this point in the history
  • Loading branch information
drekle committed May 29, 2019
1 parent 7c53b35 commit 7b433cf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
8 changes: 8 additions & 0 deletions pkg/resources/openstack/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ func (os *clusterDiscoveryOS) ListNetwork() ([]*resources.Resource, error) {
resourceTrackers = append(resourceTrackers, resourceTracker)

}

// Ports
portTrackers, err := os.ListPorts(network)
if err != nil {
return resourceTrackers, err
}
resourceTrackers = append(resourceTrackers, portTrackers...)

resourceTracker := &resources.Resource{
Name: network.Name,
ID: network.ID,
Expand Down
1 change: 0 additions & 1 deletion pkg/resources/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func ListResources(cloud openstack.OpenstackCloud, clusterName string) (map[stri
os.ListInstances,
os.ListServerGroups,
os.ListVolumes,
os.ListPorts,
os.ListSecurityGroups,
os.ListNetwork,
os.ListDNSRecordsets,
Expand Down
32 changes: 16 additions & 16 deletions pkg/resources/openstack/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,39 @@ limitations under the License.
package openstack

import (
"strings"

"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
"k8s.io/kops/pkg/resources"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/openstack"
)

const (
typePort = "Port"
typePort = "Port"
typeDynamicPort = "DynamicPort"

This comment has been minimized.

Copy link
@zetaab

zetaab May 30, 2019

Member

Is this used in any function? If not please remove

This comment has been minimized.

Copy link
@drekle

drekle May 31, 2019

Author Contributor

sure, missed this

)

func (os *clusterDiscoveryOS) ListPorts() ([]*resources.Resource, error) {
func (os *clusterDiscoveryOS) ListPorts(network networks.Network) ([]*resources.Resource, error) {
var resourceTrackers []*resources.Resource

ports, err := os.osCloud.ListPorts(ports.ListOpts{})
ports, err := os.osCloud.ListPorts(ports.ListOpts{
TenantID: network.ProjectID,
NetworkID: network.ID,
})
if err != nil {
return nil, err
}

for _, port := range ports {
clusteReplaced := strings.Replace(os.clusterName, ".", "-", -1)
if strings.HasSuffix(port.Name, clusteReplaced) {
resourceTracker := &resources.Resource{
Name: port.Name,
ID: port.ID,
Type: typePort,
Deleter: func(cloud fi.Cloud, r *resources.Resource) error {
return cloud.(openstack.OpenstackCloud).DeletePort(r.ID)
},
}
resourceTrackers = append(resourceTrackers, resourceTracker)
resourceTracker := &resources.Resource{
Name: port.Name,
ID: port.ID,
Type: typePort,
Deleter: func(cloud fi.Cloud, r *resources.Resource) error {
return cloud.(openstack.OpenstackCloud).DeletePort(r.ID)
},
}
resourceTrackers = append(resourceTrackers, resourceTracker)
}
return resourceTrackers, nil
}

0 comments on commit 7b433cf

Please sign in to comment.