dsl struct tags; wip
diff --git a/openstack/db/v1/databases/requests.go b/openstack/db/v1/databases/requests.go
index 18e1af5..7338112 100644
--- a/openstack/db/v1/databases/requests.go
+++ b/openstack/db/v1/databases/requests.go
@@ -13,52 +13,35 @@
// CreateOpts is the struct responsible for configuring a database; often in
// the context of an instance.
type CreateOpts struct {
- // [REQUIRED] Specifies the name of the database. Valid names can be composed
+ // Specifies the name of the database. Valid names can be composed
// of the following characters: letters (either case); numbers; these
// characters '@', '?', '#', ' ' but NEVER beginning a name string; '_' is
// permitted anywhere. Prohibited characters that are forbidden include:
// single quotes, double quotes, back quotes, semicolons, commas, backslashes,
// and forward slashes.
- Name string
-
- // [OPTIONAL] Set of symbols and encodings. The default character set is
+ Name string `json:"name" required:"true"`
+ // Set of symbols and encodings. The default character set is
// "utf8". See http://dev.mysql.com/doc/refman/5.1/en/charset-mysql.html for
// supported character sets.
- CharSet string
-
- // [OPTIONAL] Set of rules for comparing characters in a character set. The
+ CharSet string `json:"character_set,omitempty"`
+ // Set of rules for comparing characters in a character set. The
// default value for collate is "utf8_general_ci". See
// http://dev.mysql.com/doc/refman/5.1/en/charset-mysql.html for supported
// collations.
- Collate string
+ Collate string `json:"collate,omitempty"`
}
// ToMap is a helper function to convert individual DB create opt structures
// into sub-maps.
-func (opts CreateOpts) ToMap() (map[string]string, error) {
- if opts.Name == "" {
- err := gophercloud.ErrMissingInput{}
- err.Function = "databases.ToMap"
- err.Argument = "databases.CreateOpts.Name"
- }
+func (opts CreateOpts) ToMap() (map[string]interface{}, error) {
if len(opts.Name) > 64 {
err := gophercloud.ErrInvalidInput{}
- err.Function = "databases.ToMap"
err.Argument = "databases.CreateOpts.Name"
err.Value = opts.Name
err.Info = "Must be less than 64 chars long"
return nil, err
}
-
- db := map[string]string{"name": opts.Name}
-
- if opts.CharSet != "" {
- db["character_set"] = opts.CharSet
- }
- if opts.Collate != "" {
- db["collate"] = opts.Collate
- }
- return db, nil
+ return gophercloud.BuildRequestBody(opts, "")
}
// BatchCreateOpts allows for multiple databases to created and modified.
@@ -66,7 +49,7 @@
// ToDBCreateMap renders a JSON map for creating DBs.
func (opts BatchCreateOpts) ToDBCreateMap() (map[string]interface{}, error) {
- dbs := make([]map[string]string, len(opts))
+ dbs := make([]map[string]interface{}, len(opts))
for i, db := range opts {
dbMap, err := db.ToMap()
if err != nil {
@@ -80,41 +63,29 @@
// Create will create a new database within the specified instance. If the
// specified instance does not exist, a 404 error will be returned.
func Create(client *gophercloud.ServiceClient, instanceID string, opts CreateOptsBuilder) CreateResult {
- var res CreateResult
-
- reqBody, err := opts.ToDBCreateMap()
+ var r CreateResult
+ b, err := opts.ToDBCreateMap()
if err != nil {
- res.Err = err
- return res
+ r.Err = err
+ return r
}
-
- _, res.Err = client.Request("POST", baseURL(client, instanceID), &gophercloud.RequestOpts{
- JSONBody: &reqBody,
- OkCodes: []int{202},
- })
-
- return res
+ _, r.Err = client.Post(baseURL(client, instanceID), &b, nil, nil)
+ return r
}
// List will list all of the databases for a specified instance. Note: this
// operation will only return user-defined databases; it will exclude system
// databases like "mysql", "information_schema", "lost+found" etc.
func List(client *gophercloud.ServiceClient, instanceID string) pagination.Pager {
- createPageFn := func(r pagination.PageResult) pagination.Page {
+ return pagination.NewPager(client, baseURL(client, instanceID), func(r pagination.PageResult) pagination.Page {
return DBPage{pagination.LinkedPageBase{PageResult: r}}
- }
-
- return pagination.NewPager(client, baseURL(client, instanceID), createPageFn)
+ })
}
// Delete will permanently delete the database within a specified instance.
// All contained data inside the database will also be permanently deleted.
func Delete(client *gophercloud.ServiceClient, instanceID, dbName string) DeleteResult {
- var res DeleteResult
-
- _, res.Err = client.Request("DELETE", dbURL(client, instanceID, dbName), &gophercloud.RequestOpts{
- OkCodes: []int{202},
- })
-
- return res
+ var r DeleteResult
+ _, r.Err = client.Delete(dbURL(client, instanceID, dbName), nil)
+ return r
}