Beispiel #1
0
// CreateUser will issue a POST request to create users for the instance.
func (databaseService Service) CreateUser(instanceID string, params ...UserParameter) error {

	var inContainer = createUsersParametersContainer{params}
	reqURL, err := databaseService.buildRequestURL("/instances/", instanceID, "/users")
	if err != nil {
		return err
	}

	return misc.PostJSON(reqURL, databaseService.authenticator, &inContainer, nil)
}
// EnableRoot will issue a delete query to delete the specified database instance.
func (databaseService Service) EnableRoot(instanceID string) (UserParameter, error) {
	reqURL, err := databaseService.buildRequestURL("/instances/", instanceID, "/root")
	if err != nil {
		return UserParameter{}, err
	}

	var outContainer = userParameterContainer{}
	err = misc.PostJSON(reqURL, databaseService.authenticator, nil, &outContainer)
	return outContainer.User, err
}
// RestoreBackupInstance will issue a POST request to create a new Backup .
func (databaseService Service) RestoreBackupInstance(params RestoreBackupParameters) (InstanceDetail, error) {
	var inContainer = restoreBackupInstanceContainer{params}
	reqURL, err := databaseService.buildRequestURL("/instances")
	if err != nil {
		return InstanceDetail{}, err
	}

	var outContainer = InstanceDetailContainer{}
	err = misc.PostJSON(reqURL, databaseService.authenticator, &inContainer, &outContainer)
	return outContainer.Instance, err
}
Beispiel #4
0
// CreatePort issues a POST to create the specified port and return a PortResponse.
func (networkService Service) CreatePort(parameters CreatePortParameters) (PortResponse, error) {
	parametersContainer := createPortContainer{Port: parameters}
	portResponse := portResp{}
	reqURL, err := networkService.buildRequestURL("/ports")
	if err != nil {
		return portResponse.Port, err
	}

	err = misc.PostJSON(reqURL, networkService.authenticator, parametersContainer, &portResponse)
	return portResponse.Port, err
}
Beispiel #5
0
// CreateVolume will send a POST request to create a new volume with the specified parameters.
func (blockStorageService Service) CreateVolume(parameters CreateVolumeParameters) (Volume, error) {
	cIn := volumeCreateParametersContainer{Volume: parameters}
	cOut := volumeContainer{Volume: Volume{}}
	reqURL, err := blockStorageService.buildRequestURL("/volumes")
	if err != nil {
		return cOut.Volume, err
	}

	err = misc.PostJSON(reqURL, blockStorageService.authenticator, cIn, &cOut)
	return cOut.Volume, err
}
Beispiel #6
0
// CreateSubnet issues a GET request to add a Subnet with the specified parameters
// and returns the Subnet created.
func (networkService Service) CreateSubnet(parameters CreateSubnetParameters) (SubnetResponse, error) {
	parametersContainer := createSubnetContainer{Subnet: parameters}
	response := subnetResp{}
	reqURL, err := networkService.buildRequestURL("/subnets")
	if err != nil {
		return response.Subnet, err
	}

	err = misc.PostJSON(reqURL, networkService.authenticator, parametersContainer, &response)
	return response.Subnet, err
}
// CreateFloatingIP will issue a Post query creates a new floating ip and return the created value.
func (computeService Service) CreateFloatingIP(pool string) (FloatingIP, error) {
	var requestParameters = createFloatingIPRequest{Pool: pool}
	var r = floatingIPResp{}
	reqURL, err := computeService.buildRequestURL("/os-floating-ips")
	if err != nil {
		return r.FloatingIP, err
	}

	err = misc.PostJSON(reqURL, computeService.authenticator, requestParameters, &r)

	return r.FloatingIP, err
}
// CreateSecurityGroupRule creates a new security group rule in the specified parent.
func (computeService Service) CreateSecurityGroupRule(sgr CreateSecurityGroupRuleParameters) (SecurityGroupRule, error) {
	ruleContainer := securityGroupRuleCreateContainer{SecurityGroupRule: sgr}
	r := securityGroupRuleContainer{}
	reqURL, err := computeService.buildRequestURL("/os-security-group-rules")
	if err != nil {
		return r.SecurityGroupRule, err
	}

	err = misc.PostJSON(reqURL, computeService.authenticator, ruleContainer, &r)

	return r.SecurityGroupRule, err
}
// CreateSecurityGroup will issue a Post query creates a new security group and returns the created value.
func (computeService Service) CreateSecurityGroup(parameters CreateSecurityGroupParameters) (SecurityGroup, error) {
	var requestParameters = createSecurityGroupContainer{SecurityGroup: parameters}
	var r = securityGroupContainer{}
	reqURL, err := computeService.buildRequestURL("/os-security-groups")
	if err != nil {
		return r.SecurityGroup, err
	}

	err = misc.PostJSON(reqURL, computeService.authenticator, requestParameters, &r)

	return r.SecurityGroup, err
}
Beispiel #10
0
// CreateBackup will issue a POST request to create a new Backup.
func (databaseService Service) CreateBackup(params CreateBackupParameters) (Backup, error) {

	var inContainer = createBackupContainer{params}
	reqURL, err := databaseService.buildRequestURL("/backups")
	if err != nil {
		return Backup{}, err
	}

	var outContainer = backupContainer{}
	err = misc.PostJSON(reqURL, databaseService.authenticator, &inContainer, &outContainer)
	return outContainer.Backup, err
}
Beispiel #11
0
func TestPostJsonWithValidResponse(t *testing.T) {
	var apiServer = testUtil.CreatePostJSONTestRequestServer(t, token, `{"id":"id1","name":"Chris"}`, "", `{"id":"id1","name":"name"}`)
	defer apiServer.Close()
	actual := TestStruct{}
	ti := TestStruct{ID: "id1", Name: "name"}

	err := misc.PostJSON(apiServer.URL, token, *http.DefaultClient, ti, &actual)
	testUtil.IsNil(t, err)
	expected := TestStruct{ID: "id1", Name: "Chris"}

	testUtil.Equals(t, expected, actual)
}
Beispiel #12
0
// CreateRouter will issue a Post query creates a new security group and returns the created value.
func (networkService Service) CreateRouter(networkID string) (Router, error) {
	var requestParameters = createRouterContainer{CreateRouter: createRouter{GatewayInfo: ExternalGatewayInfo{NetworkID: networkID}}}
	var r = routerContainer{}

	reqURL, err := networkService.buildRequestURL("/routers")
	if err != nil {
		return r.Router, err
	}

	err = misc.PostJSON(reqURL, networkService.authenticator, requestParameters, &r)

	return r.Router, err
}