-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7,502 changed files
with
211,061 additions
and
1,095,605 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
# | ||
# [prune] | ||
# non-go = false | ||
# go-tests = true | ||
# unused-packages = true | ||
|
||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "github.com/gophercloud/gophercloud" | ||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "github.com/gophercloud/utils" | ||
|
||
[[constraint]] | ||
name = "github.com/hashicorp/terraform" | ||
version = "0.11.13" | ||
|
||
[prune] | ||
go-tests = true | ||
unused-packages = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// +build acceptance | ||
|
||
package ironic | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package ironic | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/gophercloud/gophercloud" | ||
"github.com/gophercloud/gophercloud/openstack/baremetal/v1/allocations" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
// Schema resource definition for an Ironic allocation. | ||
func resourceAllocationV1() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAllocationV1Create, | ||
Read: resourceAllocationV1Read, | ||
Delete: resourceAllocationV1Delete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"resource_class": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"candidate_nodes": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"traits": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"extra": { | ||
Type: schema.TypeMap, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"node_uuid": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"state": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"last_error": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// Create an allocation, including driving Ironic's state machine | ||
func resourceAllocationV1Create(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*gophercloud.ServiceClient) | ||
|
||
result, err := allocations.Create(client, allocationSchemaToCreateOpts(d)).Extract() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(result.UUID) | ||
|
||
// Wait for state to change from allocating | ||
var state string | ||
timeout := 1 * time.Minute | ||
checkInterval := 5 * time.Second | ||
|
||
|
||
for resourceAllocationV1Read(d, meta) ; state == "allocating" || state == ""; resourceAllocationV1Read(d, meta) { | ||
state = d.Get("state").(string) | ||
log.Printf("[DEBUG] Requested allocation %s; current state is '%s'\n", d.Id(), state) | ||
|
||
time.Sleep(checkInterval) | ||
timeout -= checkInterval | ||
if timeout < 0 { | ||
return fmt.Errorf("timed out waiting for allocation") | ||
} | ||
} | ||
|
||
if state == "error" { | ||
err := d.Get("last_error").(string) | ||
resourceAllocationV1Delete(d, meta) | ||
d.SetId("") | ||
return fmt.Errorf("error creating resource: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Read the allocation's data from Ironic | ||
func resourceAllocationV1Read(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*gophercloud.ServiceClient) | ||
|
||
result, err := allocations.Get(client, d.Id()).Extract() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.Set("name", result.Name) | ||
d.Set("resource_class", result.ResourceClass) | ||
d.Set("candidate_nodes", result.CandidateNodes) | ||
d.Set("traits", result.Traits) | ||
d.Set("extra", result.Extra) | ||
d.Set("node_uuid", result.NodeUUID) | ||
d.Set("state", result.State) | ||
d.Set("last_error", result.LastError) | ||
|
||
return nil | ||
} | ||
|
||
// Delete an allocation from Ironic | ||
func resourceAllocationV1Delete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*gophercloud.ServiceClient) | ||
return allocations.Delete(client, d.Id()).ExtractErr() | ||
} | ||
|
||
func allocationSchemaToCreateOpts(d *schema.ResourceData) *allocations.CreateOpts { | ||
candidateNodesRaw := d.Get("candidate_nodes").([]interface{}) | ||
traitsRaw := d.Get("traits").([]interface{}) | ||
extraRaw := d.Get("extra").(map[string]interface{}) | ||
|
||
candidateNodes := make([]string, len(candidateNodesRaw)) | ||
for i := range candidateNodesRaw { | ||
candidateNodes[i] = candidateNodesRaw[i].(string) | ||
} | ||
|
||
traits := make([]string, len(traitsRaw)) | ||
for i := range traitsRaw { | ||
traits[i] = traitsRaw[i].(string) | ||
} | ||
|
||
extra := make(map[string]string) | ||
for k, v := range extraRaw { | ||
extra[k] = v.(string) | ||
} | ||
|
||
return &allocations.CreateOpts{ | ||
Name: d.Get("name").(string), | ||
ResourceClass: d.Get("resource_class").(string), | ||
CandidateNodes: candidateNodes, | ||
Traits: traits, | ||
Extra: extra, | ||
} | ||
} |
Oops, something went wrong.