-
Notifications
You must be signed in to change notification settings - Fork 3
Implement Nebius security group management framework #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,43 @@ package v1 | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
v1 "github.com/brevdev/compute/pkg/v1" | ||
) | ||
|
||
func (c *NebiusClient) CreateInstance(_ context.Context, _ v1.CreateInstanceAttrs) (*v1.Instance, error) { | ||
return nil, v1.ErrNotImplemented | ||
func (c *NebiusClient) CreateInstance(ctx context.Context, attrs v1.CreateInstanceAttrs) (*v1.Instance, error) { | ||
securityGroupID, err := c.ensureClusterSecurityGroup(ctx, attrs) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to ensure cluster security group: %w", err) | ||
} | ||
|
||
instance, err := c.createInstanceWithSecurityGroup(ctx, attrs, securityGroupID) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create instance with security group: %w", err) | ||
} | ||
|
||
return instance, nil | ||
} | ||
|
||
func (c *NebiusClient) ensureClusterSecurityGroup(_ context.Context, attrs v1.CreateInstanceAttrs) (string, error) { | ||
clusterID := c.getClusterIDFromAttrs(attrs) | ||
_ = fmt.Sprintf("brev-cluster-%s", clusterID) | ||
|
||
return "", fmt.Errorf("cluster security group creation not yet implemented - need to use Nebius VPC service") | ||
} | ||
|
||
func (c *NebiusClient) createInstanceWithSecurityGroup(_ context.Context, _ v1.CreateInstanceAttrs, _ string) (*v1.Instance, error) { | ||
return nil, fmt.Errorf("instance creation with security group not yet implemented - need to use Nebius Compute service") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please implement |
||
} | ||
|
||
func (c *NebiusClient) getClusterIDFromAttrs(attrs v1.CreateInstanceAttrs) string { | ||
if attrs.Tags != nil { | ||
if clusterID, exists := attrs.Tags["cluster_id"]; exists { | ||
return clusterID | ||
} | ||
} | ||
return "default" | ||
} | ||
|
||
func (c *NebiusClient) GetInstance(_ context.Context, _ v1.CloudProviderInstanceID) (*v1.Instance, error) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,58 @@ package v1 | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
v1 "github.com/brevdev/compute/pkg/v1" | ||
) | ||
|
||
func (c *NebiusClient) AddFirewallRulesToInstance(_ context.Context, _ v1.AddFirewallRulesToInstanceArgs) error { | ||
return v1.ErrNotImplemented | ||
func (c *NebiusClient) AddFirewallRulesToInstance(ctx context.Context, args v1.AddFirewallRulesToInstanceArgs) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it may be useful to look at the other repo devplane/internal/cloud/aws which implements security groups and maps args -> sg correctly. |
||
securityGroupID, err := c.getOrCreateSecurityGroupForInstance(ctx, args.InstanceID) | ||
if err != nil { | ||
return fmt.Errorf("failed to get or create security group for instance %s: %w", args.InstanceID, err) | ||
} | ||
|
||
err = c.addFirewallRulesToSecurityGroup(ctx, securityGroupID, args.FirewallRules) | ||
if err != nil { | ||
return fmt.Errorf("failed to add firewall rules to security group %s: %w", securityGroupID, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *NebiusClient) RevokeSecurityGroupRules(ctx context.Context, args v1.RevokeSecurityGroupRuleArgs) error { | ||
securityGroupID, err := c.getSecurityGroupForInstance(ctx, args.InstanceID) | ||
if err != nil { | ||
return fmt.Errorf("failed to get security group for instance %s: %w", args.InstanceID, err) | ||
} | ||
|
||
err = c.removeSecurityGroupRules(ctx, securityGroupID, args.SecurityGroupRuleIDs) | ||
if err != nil { | ||
return fmt.Errorf("failed to remove security group rules from %s: %w", securityGroupID, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *NebiusClient) getOrCreateSecurityGroupForInstance(_ context.Context, instanceID v1.CloudProviderInstanceID) (string, error) { | ||
clusterID := c.getClusterIDFromInstance(instanceID) | ||
_ = fmt.Sprintf("brev-cluster-%s", clusterID) | ||
|
||
return "", fmt.Errorf("security group management not yet implemented - need to use Nebius VPC service") | ||
} | ||
|
||
func (c *NebiusClient) getSecurityGroupForInstance(_ context.Context, _ v1.CloudProviderInstanceID) (string, error) { | ||
return "", fmt.Errorf("security group lookup not yet implemented - need to use Nebius VPC service") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please attempt to implement |
||
} | ||
|
||
func (c *NebiusClient) addFirewallRulesToSecurityGroup(_ context.Context, _ string, _ v1.FirewallRules) error { | ||
return fmt.Errorf("firewall rule addition not yet implemented - need to use Nebius VPC service") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please attempt to implement |
||
} | ||
|
||
func (c *NebiusClient) removeSecurityGroupRules(_ context.Context, _ string, _ []string) error { | ||
return fmt.Errorf("security group rule removal not yet implemented - need to use Nebius VPC service") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please attempt to implement |
||
} | ||
|
||
func (c *NebiusClient) RevokeSecurityGroupRules(_ context.Context, _ v1.RevokeSecurityGroupRuleArgs) error { | ||
return v1.ErrNotImplemented | ||
func (c *NebiusClient) getClusterIDFromInstance(_ v1.CloudProviderInstanceID) string { | ||
return "default" | ||
} |
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.
please implement refer to golang sdk https://github.com/nebius/gosdk