github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/baremetal/v1/baremetal.go (about) 1 package v1 2 3 import ( 4 "testing" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/internal/acceptance/tools" 8 "github.com/gophercloud/gophercloud/openstack/baremetal/v1/allocations" 9 "github.com/gophercloud/gophercloud/openstack/baremetal/v1/nodes" 10 "github.com/gophercloud/gophercloud/openstack/baremetal/v1/ports" 11 ) 12 13 // CreateNode creates a basic node with a randomly generated name. 14 func CreateNode(t *testing.T, client *gophercloud.ServiceClient) (*nodes.Node, error) { 15 name := tools.RandomString("ACPTTEST", 16) 16 t.Logf("Attempting to create bare metal node: %s", name) 17 18 node, err := nodes.Create(client, nodes.CreateOpts{ 19 Name: name, 20 Driver: "ipmi", 21 BootInterface: "ipxe", 22 RAIDInterface: "agent", 23 DriverInfo: map[string]interface{}{ 24 "ipmi_port": "6230", 25 "ipmi_username": "admin", 26 "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz", 27 "ipmi_address": "192.168.122.1", 28 "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz", 29 "ipmi_password": "admin", 30 }, 31 }).Extract() 32 33 return node, err 34 } 35 36 // DeleteNode deletes a bare metal node via its UUID. 37 func DeleteNode(t *testing.T, client *gophercloud.ServiceClient, node *nodes.Node) { 38 err := nodes.Delete(client, node.UUID).ExtractErr() 39 if err != nil { 40 t.Fatalf("Unable to delete node %s: %s", node.UUID, err) 41 } 42 43 t.Logf("Deleted server: %s", node.UUID) 44 } 45 46 // CreateAllocation creates an allocation 47 func CreateAllocation(t *testing.T, client *gophercloud.ServiceClient) (*allocations.Allocation, error) { 48 name := tools.RandomString("ACPTTEST", 16) 49 t.Logf("Attempting to create bare metal allocation: %s", name) 50 51 allocation, err := allocations.Create(client, allocations.CreateOpts{ 52 Name: name, 53 ResourceClass: "baremetal", 54 }).Extract() 55 56 return allocation, err 57 } 58 59 // DeleteAllocation deletes a bare metal allocation via its UUID. 60 func DeleteAllocation(t *testing.T, client *gophercloud.ServiceClient, allocation *allocations.Allocation) { 61 err := allocations.Delete(client, allocation.UUID).ExtractErr() 62 if err != nil { 63 t.Fatalf("Unable to delete allocation %s: %s", allocation.UUID, err) 64 } 65 66 t.Logf("Deleted allocation: %s", allocation.UUID) 67 } 68 69 // CreateFakeNode creates a node with fake-hardware to use for port tests. 70 func CreateFakeNode(t *testing.T, client *gophercloud.ServiceClient) (*nodes.Node, error) { 71 name := tools.RandomString("ACPTTEST", 16) 72 t.Logf("Attempting to create bare metal node: %s", name) 73 74 node, err := nodes.Create(client, nodes.CreateOpts{ 75 Name: name, 76 Driver: "fake-hardware", 77 BootInterface: "fake", 78 DriverInfo: map[string]interface{}{ 79 "ipmi_port": "6230", 80 "ipmi_username": "admin", 81 "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz", 82 "ipmi_address": "192.168.122.1", 83 "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz", 84 "ipmi_password": "admin", 85 }, 86 }).Extract() 87 88 return node, err 89 } 90 91 // CreatePort - creates a port for a node with a fixed Address 92 func CreatePort(t *testing.T, client *gophercloud.ServiceClient, node *nodes.Node) (*ports.Port, error) { 93 mac := "e6:72:1f:52:00:f4" 94 t.Logf("Attempting to create Port for Node: %s with Address: %s", node.UUID, mac) 95 96 iTrue := true 97 port, err := ports.Create(client, ports.CreateOpts{ 98 NodeUUID: node.UUID, 99 Address: mac, 100 PXEEnabled: &iTrue, 101 }).Extract() 102 103 return port, err 104 } 105 106 // DeletePort - deletes a port via its UUID 107 func DeletePort(t *testing.T, client *gophercloud.ServiceClient, port *ports.Port) { 108 err := ports.Delete(client, port.UUID).ExtractErr() 109 if err != nil { 110 t.Fatalf("Unable to delete port %s: %s", port.UUID, err) 111 } 112 113 t.Logf("Deleted port: %s", port.UUID) 114 115 }