Documentation ¶
Index ¶
- Constants
- func AwaitUntilCompletion(gen operationGenerator) error
- func ListLocations(service GoogleService, project string) ([]string, error)
- func ListRecommendations(service GoogleService, project string, numConcurrentCalls int, task *Task) ([]*gcloudRecommendation, error)
- type GoogleService
- type ListResult
- type ProjectRequirements
- type Requirement
- type Task
Constants ¶
const ( // RequirementFailed corresponds to the failed status of requirement RequirementFailed = "FAILED" // RequirementCompleted corresponds to the completed status of requirement RequirementCompleted = "COMPLETED" )
Variables ¶
This section is empty.
Functions ¶
func AwaitUntilCompletion ¶
func AwaitUntilCompletion(gen operationGenerator) error
AwaitUntilCompletion takes a function that needs to be called repeatedly
to check if a process (some Google Service request) has finished.
Such a function is usually constructed by wrapping a .Do() call
func ListLocations ¶
func ListLocations(service GoogleService, project string) ([]string, error)
ListLocations return the list of all locations per project(zones and regions). Exactly one of returned values will be non-nil.
func ListRecommendations ¶
func ListRecommendations(service GoogleService, project string, numConcurrentCalls int, task *Task) ([]*gcloudRecommendation, error)
ListRecommendations returns the list of recommendations for a Cloud project from googleRecommenders. Requires the recommender.*.list IAM permissions for the recommenders. numConcurrentCalls specifies the maximum number of concurrent calls to ListRecommendations method, non-positive values are ignored, instead the default value is used. task structure tracks the progress of the function.
Types ¶
type GoogleService ¶
type GoogleService interface { // changes the machine type of an instance ChangeMachineType(project, zone, instance, machineType string) error // creates a snapshot of a disk CreateSnapshot(project, zone, disk, name string) error // deletes persistent disk DeleteDisk(project, zone, disk string) error // gets the specified instance resource GetInstance(project string, zone string, instance string) (*compute.Instance, error) // lists whether the requirements have been met for all APIs (APIs enabled). ListAPIRequirements(project string, apis []string) ([]*Requirement, error) // lists whether the requirements have been met for all required permissions. ListPermissionRequirements(project string, permissions [][]string) ([]*Requirement, error) // lists projects ListProjects() ([]string, error) // listing recommendations for specified project, zone and recommender ListRecommendations(project, location, recommenderID string) ([]*gcloudRecommendation, error) // listing every zone available for the project methods ListZonesNames(project string) ([]string, error) // listing every region available for the project methods ListRegionsNames(project string) ([]string, error) // stops the specified instance StopInstance(project, zone, instance string) error }
GoogleService is the inferface that provides methods required to list recommendations and apply them
func NewGoogleService ¶
func NewGoogleService(ctx context.Context) (GoogleService, error)
NewGoogleService creates new googleServices. If creation failed the error will be non-nil.
type ListResult ¶
type ListResult struct {
// contains filtered or unexported fields
}
ListResult contains information about listing recommendations for all projects. If user doesn't have enough permissions for the project, the requirements, including failed ones, are listed in failedProjects. Otherwise, recommendations for the project are appended to recommendations.
func ListAllProjectsRecommendations ¶
func ListAllProjectsRecommendations(service GoogleService, numConcurrentCalls int, task *Task) (*ListResult, error)
ListAllProjectsRecommendations gets all projects for which user has projects.get permission. If the user has enough permissions to apply and list recommendations, recommendations for projects are listed. Otherwise, projects requirements, including failed ones, are added to `failedProjects` to help show warnings to the user. task structure tracks how many subtasks have been done already.
type ProjectRequirements ¶
type ProjectRequirements struct { Project string `json:"project"` Requirements []*Requirement `json:"requirements"` }
ProjectRequirements contains information about permissions for the user for the project.
func ListRequirements ¶
func ListRequirements(s GoogleService, projects []string, task *Task) ([]*ProjectRequirements, error)
ListRequirements lists the requirements and their statuses for every project. task structure tracks how many projects have been processed already.
type Requirement ¶
type Requirement struct { Name string `json:"name"` Status string `json:"status"` ErrorMessage string `json:"errorMessage"` }
Requirement contains information about the required permission or api. Status states whether permission is given and api is enabled. If Status if FAILED, ErrorMessage will contain information about the problem.
func ListProjectRequirements ¶
func ListProjectRequirements(s GoogleService, project string) ([]*Requirement, error)
ListProjectRequirements is a function that lists all permissions and APIs and their statuses for a project. If all statuses are equal to RequirementCompleted, user has all required permissions.
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task is the structure that helps get the percentage of work done. GetProgress method is thread-safe. IncrementDone and GetNextSubtask is thread-safe, but GetProgress is calculated in assumption that all subtasks, except lower-level subtasks with no subtasks, will be done consequently.
func (*Task) GetNextSubtask ¶
GetNextSubtask returns the pointer to next not done subtask
func (*Task) GetProgress ¶
GetProgress returns the fraction of work done. Assumes that all subtasks, except the subtasks, that don't have their own subtasks are done subseequently Returned values are numerator and denominator of that fraction. If not all work is done numerator is garantueed to be less than denominator.
func (*Task) SetNumberOfSubtasks ¶
SetNumberOfSubtasks is used to set number of subtasks in the task