Skip to content
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

WIP: Protection rule and Recovery plan(DR Runbook) resources and datasources #125

Closed
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ linters-settings:
# Default is 120. '\t' is counted as 1 character.
# set our project to 200, as things like v3_structs with inline comments end up being a touch long
# also, for anyone using vscode, use the following configs:
# "rewrap.wrappingColumn": 200 ... requires the rewrap plugin
# "editor.rulers": [200]
# "rewrap.wrappingColumn": 140 ... requires the rewrap plugin
# "editor.rulers": [140]
line-length: 200

linters:
Expand Down
242 changes: 242 additions & 0 deletions client/v3/v3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ type Service interface {
ListAllProject() (*ProjectListResponse, error)
UpdateProject(uuid string, body *Project) (*Project, error)
DeleteProject(uuid string) error
GetProtectionRule(uuid string) (*ProtectionRuleResponse, error)
ListProtectionRules(getEntitiesRequest *DSMetadata) (*ProtectionRulesListResponse, error)
ListAllProtectionRules() (*ProtectionRulesListResponse, error)
CreateProtectionRule(request *ProtectionRuleInput) (*ProtectionRuleResponse, error)
UpdateProtectionRule(uuid string, body *ProtectionRuleInput) (*ProtectionRuleResponse, error)
DeleteProtectionRule(uuid string) (*DeleteResponse, error)
GetRecoveryPlan(uuid string) (*RecoveryPlanResponse, error)
ListRecoveryPlans(getEntitiesRequest *DSMetadata) (*RecoveryPlanListResponse, error)
ListAllRecoveryPlans() (*RecoveryPlanListResponse, error)
CreateRecoveryPlan(request *RecoveryPlanInput) (*RecoveryPlanResponse, error)
UpdateRecoveryPlan(uuid string, body *RecoveryPlanInput) (*RecoveryPlanResponse, error)
DeleteRecoveryPlan(uuid string) (*DeleteResponse, error)
}

/*CreateVM Creates a VM
Expand Down Expand Up @@ -1296,3 +1308,233 @@ func (op Operations) DeleteProject(uuid string) error {

return op.client.Do(ctx, req, nil)
}

//GetProtectionRule ...
func (op Operations) GetProtectionRule(uuid string) (*ProtectionRuleResponse, error) {
ctx := context.TODO()

path := fmt.Sprintf("/protection_rules/%s", uuid)
protectionRule := new(ProtectionRuleResponse)

req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, err
}

return protectionRule, op.client.Do(ctx, req, protectionRule)
}

//ListProtectionRules ...
func (op Operations) ListProtectionRules(getEntitiesRequest *DSMetadata) (*ProtectionRulesListResponse, error) {
ctx := context.TODO()
path := "/protection_rules/list"

list := new(ProtectionRulesListResponse)

req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
if err != nil {
return nil, err
}

return list, op.client.Do(ctx, req, list)
}

// ListAllProtectionRules ...
func (op Operations) ListAllProtectionRules() (*ProtectionRulesListResponse, error) {
entities := make([]*ProtectionRuleResponse, 0)

resp, err := op.ListProtectionRules(&DSMetadata{
Kind: utils.StringPtr("protection_rule"),
Length: utils.Int64Ptr(itemsPerPage),
})
if err != nil {
return nil, err
}

totalEntities := utils.Int64Value(resp.Metadata.TotalMatches)
remaining := totalEntities
offset := utils.Int64Value(resp.Metadata.Offset)

if totalEntities > itemsPerPage {
for hasNext(&remaining) {
resp, err = op.ListProtectionRules(&DSMetadata{
Kind: utils.StringPtr("protection_rule"),
Length: utils.Int64Ptr(itemsPerPage),
Offset: utils.Int64Ptr(offset),
})

if err != nil {
return nil, err
}

entities = append(entities, resp.Entities...)

offset += itemsPerPage
log.Printf("[Debug] total=%d, remaining=%d, offset=%d len(entities)=%d\n", totalEntities, remaining, offset, len(entities))
}

resp.Entities = entities
}

return resp, nil
}

//CreateProtectionRule ...
func (op Operations) CreateProtectionRule(createRequest *ProtectionRuleInput) (*ProtectionRuleResponse, error) {
ctx := context.TODO()

req, err := op.client.NewRequest(ctx, http.MethodPost, "/protection_rules", createRequest)
protectionRuleResponse := new(ProtectionRuleResponse)

if err != nil {
return nil, err
}

return protectionRuleResponse, op.client.Do(ctx, req, protectionRuleResponse)
}

//UpdateProtectionRule ...
func (op Operations) UpdateProtectionRule(uuid string, body *ProtectionRuleInput) (*ProtectionRuleResponse, error) {
ctx := context.TODO()

path := fmt.Sprintf("/protection_rules/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
protectionRuleResponse := new(ProtectionRuleResponse)

if err != nil {
return nil, err
}

return protectionRuleResponse, op.client.Do(ctx, req, protectionRuleResponse)
}

//DeleteProtectionRule ...
func (op Operations) DeleteProtectionRule(uuid string) (*DeleteResponse, error) {
ctx := context.TODO()

path := fmt.Sprintf("/protection_rules/%s", uuid)

req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)

if err != nil {
return nil, err
}

return deleteResponse, op.client.Do(ctx, req, deleteResponse)
}

//GetRecoveryPlan ...
func (op Operations) GetRecoveryPlan(uuid string) (*RecoveryPlanResponse, error) {
ctx := context.TODO()

path := fmt.Sprintf("/recovery_plans/%s", uuid)
RecoveryPlan := new(RecoveryPlanResponse)

req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, err
}

return RecoveryPlan, op.client.Do(ctx, req, RecoveryPlan)
}

//ListRecoveryPlans ...
func (op Operations) ListRecoveryPlans(getEntitiesRequest *DSMetadata) (*RecoveryPlanListResponse, error) {
ctx := context.TODO()
path := "/recovery_plans/list"

list := new(RecoveryPlanListResponse)

req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
if err != nil {
return nil, err
}

return list, op.client.Do(ctx, req, list)
}

// ListAllRecoveryPlans ...
func (op Operations) ListAllRecoveryPlans() (*RecoveryPlanListResponse, error) {
entities := make([]*RecoveryPlanResponse, 0)

resp, err := op.ListRecoveryPlans(&DSMetadata{
Kind: utils.StringPtr("recovery_plan"),
Length: utils.Int64Ptr(itemsPerPage),
})
if err != nil {
return nil, err
}

totalEntities := utils.Int64Value(resp.Metadata.TotalMatches)
remaining := totalEntities
offset := utils.Int64Value(resp.Metadata.Offset)

if totalEntities > itemsPerPage {
for hasNext(&remaining) {
resp, err = op.ListRecoveryPlans(&DSMetadata{
Kind: utils.StringPtr("recovery_plan"),
Length: utils.Int64Ptr(itemsPerPage),
Offset: utils.Int64Ptr(offset),
})

if err != nil {
return nil, err
}

entities = append(entities, resp.Entities...)

offset += itemsPerPage
log.Printf("[Debug] total=%d, remaining=%d, offset=%d len(entities)=%d\n", totalEntities, remaining, offset, len(entities))
}

resp.Entities = entities
}

return resp, nil
}

//CreateRecoveryPlan ...
func (op Operations) CreateRecoveryPlan(createRequest *RecoveryPlanInput) (*RecoveryPlanResponse, error) {
ctx := context.TODO()

req, err := op.client.NewRequest(ctx, http.MethodPost, "/recovery_plans", createRequest)
RecoveryPlanResponse := new(RecoveryPlanResponse)

if err != nil {
return nil, err
}

return RecoveryPlanResponse, op.client.Do(ctx, req, RecoveryPlanResponse)
}

//UpdateRecoveryPlan ...
func (op Operations) UpdateRecoveryPlan(uuid string, body *RecoveryPlanInput) (*RecoveryPlanResponse, error) {
ctx := context.TODO()

path := fmt.Sprintf("/recovery_plans/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
RecoveryPlanResponse := new(RecoveryPlanResponse)

if err != nil {
return nil, err
}

return RecoveryPlanResponse, op.client.Do(ctx, req, RecoveryPlanResponse)
}

//DeleteRecoveryPlan ...
func (op Operations) DeleteRecoveryPlan(uuid string) (*DeleteResponse, error) {
ctx := context.TODO()

path := fmt.Sprintf("/recovery_plans/%s", uuid)

req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)

if err != nil {
return nil, err
}

return deleteResponse, op.client.Do(ctx, req, deleteResponse)
}
Loading