This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
add nics for networking #10
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package nics | ||
|
||
import ( | ||
"github.com/huaweicloud/golangsdk" | ||
) | ||
|
||
// AssociateOptsBuilder allows extensions to | ||
// add additional parameters to the associate request. | ||
type AssociateOptsBuilder interface { | ||
ToVIPAssociateMap() (map[string]interface{}, error) | ||
} | ||
|
||
// NicAssociateOpts is a struct for creation | ||
type NicAssociateOpts struct { | ||
SubnetID string `json:"subnet_id" required:"true"` | ||
IPAddress string `json:"ip_address" required:"true"` | ||
ReverseBinding bool `json:"reverse_binding" required:"true"` | ||
DeviceOwner string `json:"device_owner,omitempty"` | ||
} | ||
|
||
// AssociateOpts specifies the required information | ||
// to associate a Floating IP with an instance | ||
type AssociateOpts struct { | ||
// Nic is associated by VIP. | ||
Nic NicAssociateOpts `json:"nic" required:"true"` | ||
} | ||
|
||
// ToVIPAssociateMap constructs a request body from AssociateOpts. | ||
func (opts AssociateOpts) ToVIPAssociateMap() (map[string]interface{}, error) { | ||
return golangsdk.BuildRequestBody(opts, "") | ||
} | ||
|
||
// AssociateVIP pairs an allocated VIP with a nic. | ||
func AssociateVIP(client *golangsdk.ServiceClient, id string, ops AssociateOptsBuilder) (r AssociateResult) { | ||
b, err := ops.ToVIPAssociateMap() | ||
if err != nil { | ||
r.Err = err | ||
return | ||
} | ||
|
||
_, r.Err = client.Put(associateURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ | ||
OkCodes: []int{200}, | ||
}) | ||
|
||
return | ||
} | ||
|
||
// DisassociateOptsBuilder allows extensions to | ||
// add additional parameters to the Disassociate request. | ||
type DisassociateOptsBuilder interface { | ||
ToVIPDisassociateMap() (map[string]interface{}, error) | ||
} | ||
|
||
// NicDisassociateOpts is a struct for disassociate | ||
type NicDisassociateOpts struct { | ||
} | ||
|
||
// DisassociateOpts specifies the required information | ||
// to associate a VIP with a nic | ||
type DisassociateOpts struct { | ||
// Nic is associated by VIP. | ||
Nic NicDisassociateOpts `json:"nic" required:"true"` | ||
} | ||
|
||
// ToVIPDisassociateMap constructs a request body from DisassociateOpts. | ||
func (opts DisassociateOpts) ToVIPDisassociateMap() (map[string]interface{}, error) { | ||
return golangsdk.BuildRequestBody(opts, "") | ||
} | ||
|
||
// DisassociateVIP pairs an allocated VIP with a nic. | ||
func DisassociateVIP(client *golangsdk.ServiceClient, id string, ops DisassociateOptsBuilder) (r DisassociateResult) { | ||
b, err := ops.ToVIPDisassociateMap() | ||
if b != nil { | ||
b["subnet_id"] = "" | ||
b["ip_address"] = "" | ||
b["reverse_binding"] = false | ||
} | ||
if err != nil { | ||
r.Err = err | ||
return | ||
} | ||
|
||
_, r.Err = client.Put(disassociateURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ | ||
OkCodes: []int{200}, | ||
}) | ||
|
||
return | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package nics | ||
|
||
import "github.com/huaweicloud/golangsdk" | ||
|
||
// Nic defines results | ||
type Nic struct { | ||
PortID string `json:"port_id"` | ||
} | ||
|
||
// AssociateResult is the response from a Associate operation. | ||
type AssociateResult struct { | ||
golangsdk.Result | ||
} | ||
|
||
// Extract from AssociateResult | ||
func (r AssociateResult) Extract() (*Nic, error) { | ||
s := &Nic{} | ||
return s, r.ExtractInto(s) | ||
} | ||
|
||
// DisassociateResult is the response from a Disassociate operation. | ||
type DisassociateResult struct { | ||
golangsdk.Result | ||
} | ||
|
||
// Extract from DisassociateResult | ||
func (r DisassociateResult) Extract() (*Nic, error) { | ||
s := &Nic{} | ||
return s, r.ExtractInto(s) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package nics | ||
|
||
import "github.com/huaweicloud/golangsdk" | ||
|
||
// endpoint/cloudservers/ | ||
const ( | ||
rootPath = "cloudservers" | ||
resourcePath = "nics" | ||
) | ||
|
||
// associateURL will build associate private ip from nic | ||
func associateURL(c *golangsdk.ServiceClient, id string) string { | ||
return c.ServiceURL(rootPath, resourcePath, id) | ||
} | ||
|
||
// disassociateURL will build disassociate private ip from nic | ||
func disassociateURL(c *golangsdk.ServiceClient, id string) string { | ||
return c.ServiceURL(rootPath, resourcePath, id) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty struct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks your review