mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-12-15 16:09:39 -05:00
openstack: remove unused code
This commit is contained in:
parent
c5b17fb828
commit
bab27fbc69
6 changed files with 7 additions and 219 deletions
|
|
@ -22,21 +22,18 @@ import (
|
|||
// documentation of OpenStack Metadata Service: https://docs.openstack.org/nova/rocky/user/metadata-service.html
|
||||
|
||||
const (
|
||||
imdsMetaDataURL = "http://169.254.169.254/openstack/2018-08-27/meta_data.json"
|
||||
imdsNetworkDataURL = "http://169.254.169.254/openstack/2018-08-27/network_data.json"
|
||||
ec2ImdsBaseURL = "http://169.254.169.254/1.0/meta-data"
|
||||
maxCacheAge = 12 * time.Hour
|
||||
imdsMetaDataURL = "http://169.254.169.254/openstack/2018-08-27/meta_data.json"
|
||||
ec2ImdsBaseURL = "http://169.254.169.254/1.0/meta-data"
|
||||
maxCacheAge = 12 * time.Hour
|
||||
)
|
||||
|
||||
type imdsClient struct {
|
||||
client httpClient
|
||||
|
||||
vpcIPCache string
|
||||
vpcIPCacheTime time.Time
|
||||
networkCache networkResponse
|
||||
networkCacheTime time.Time
|
||||
cache metadataResponse
|
||||
cacheTime time.Time
|
||||
vpcIPCache string
|
||||
vpcIPCacheTime time.Time
|
||||
cache metadataResponse
|
||||
cacheTime time.Time
|
||||
}
|
||||
|
||||
// providerID returns the provider ID of the instance the function is called from.
|
||||
|
|
@ -226,30 +223,6 @@ func (c *imdsClient) vpcIP(ctx context.Context) (string, error) {
|
|||
return c.vpcIPCache, nil
|
||||
}
|
||||
|
||||
func (c *imdsClient) networkIDs(ctx context.Context) ([]string, error) {
|
||||
if c.timeForUpdate(c.networkCacheTime) || len(c.networkCache.Networks) == 0 {
|
||||
resp, err := httpGet(ctx, c.client, imdsNetworkDataURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var networkResp networkResponse
|
||||
if err := json.Unmarshal(resp, &networkResp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.networkCache = networkResp
|
||||
c.networkCacheTime = time.Now()
|
||||
}
|
||||
|
||||
var networkIDs []string
|
||||
for _, network := range c.networkCache.Networks {
|
||||
if network.NetworkID == "" {
|
||||
continue
|
||||
}
|
||||
networkIDs = append(networkIDs, network.NetworkID)
|
||||
}
|
||||
return networkIDs, nil
|
||||
}
|
||||
|
||||
func httpGet(ctx context.Context, c httpClient, url string) ([]byte, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
|
||||
if err != nil {
|
||||
|
|
@ -281,16 +254,6 @@ type metadataTags struct {
|
|||
Password string `json:"openstack-password,omitempty"`
|
||||
}
|
||||
|
||||
// networkResponse contains networkResponse with only the required values.
|
||||
type networkResponse struct {
|
||||
Networks []metadataNetwork `json:"networks,omitempty"`
|
||||
}
|
||||
|
||||
type metadataNetwork struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
NetworkID string `json:"network_id,omitempty"`
|
||||
}
|
||||
|
||||
type httpClient interface {
|
||||
Do(req *http.Request) (*http.Response, error)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue