github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetal/v1/nodes/doc.go (about)

     1  /*
     2  Package nodes provides information and interaction with the nodes API
     3  resource in the OpenStack Bare Metal service.
     4  
     5  Example to List Nodes with Detail
     6  
     7  	nodes.ListDetail(client, nodes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
     8  		nodeList, err := nodes.ExtractNodes(page)
     9  		if err != nil {
    10  			return false, err
    11  		}
    12  
    13  		for _, n := range nodeList {
    14  			// Do something
    15  		}
    16  
    17  		return true, nil
    18  	})
    19  
    20  Example to List Nodes
    21  
    22  	listOpts := nodes.ListOpts{
    23  		ProvisionState: nodes.Deploying,
    24  		Fields:         []string{"name"},
    25  	}
    26  
    27  	nodes.List(client, listOpts).EachPage(func(page pagination.Page) (bool, error) {
    28  		nodeList, err := nodes.ExtractNodes(page)
    29  		if err != nil {
    30  			return false, err
    31  		}
    32  
    33  		for _, n := range nodeList {
    34  			// Do something
    35  		}
    36  
    37  		return true, nil
    38  	})
    39  
    40  Example to Create Node
    41  
    42  	createOpts := nodes.CreateOpts
    43  		Driver:        "ipmi",
    44  		BootInterface: "pxe",
    45  		Name:          "coconuts",
    46  		DriverInfo: map[string]interface{}{
    47  			"ipmi_port":      "6230",
    48  			"ipmi_username":  "admin",
    49  			"deploy_kernel":  "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
    50  			"ipmi_address":   "192.168.122.1",
    51  			"deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
    52  			"ipmi_password":  "admin",
    53  		},
    54  	}
    55  
    56  	createNode, err := nodes.Create(client, createOpts).Extract()
    57  	if err != nil {
    58  		panic(err)
    59  	}
    60  
    61  Example to Get Node
    62  
    63  	showNode, err := nodes.Get(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474").Extract()
    64  	if err != nil {
    65  		panic(err)
    66  	}
    67  
    68  Example to Update Node
    69  
    70  	updateOpts := nodes.UpdateOpts{
    71  		nodes.UpdateOperation{
    72  			Op:    ReplaceOp,
    73  			Path:  "/maintenance",
    74  			Value: "true",
    75  		},
    76  	}
    77  
    78  	updateNode, err := nodes.Update(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474", updateOpts).Extract()
    79  	if err != nil {
    80  		panic(err)
    81  	}
    82  
    83  Example to Delete Node
    84  
    85  	err = nodes.Delete(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474").ExtractErr()
    86  	if err != nil {
    87  		panic(err)
    88  	}
    89  
    90  Example to Validate Node
    91  
    92  	validation, err := nodes.Validate(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8").Extract()
    93  	if err != nil {
    94  		panic(err)
    95  	}
    96  
    97  Example to inject non-masking interrupts
    98  
    99  	err := nodes.InjectNMI(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8").ExtractErr()
   100  	if err != nil {
   101  		panic(err)
   102  	}
   103  
   104  Example to get array of supported boot devices for a node
   105  
   106  	bootDevices, err := nodes.GetSupportedBootDevices(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8").Extract()
   107  	if err != nil {
   108  		panic(err)
   109  	}
   110  
   111  Example to set boot device for a node
   112  
   113  	bootOpts := nodes.BootDeviceOpts{
   114  		BootDevice: "pxe",
   115  		Persistent: false,
   116  	}
   117  
   118  	err := nodes.SetBootDevice(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8", bootOpts).ExtractErr()
   119  	if err != nil {
   120  		panic(err)
   121  	}
   122  
   123  Example to get boot device for a node
   124  
   125  	bootDevice, err := nodes.GetBootDevice(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8").Extract()
   126  	if err != nil {
   127  		panic(err)
   128  	}
   129  
   130  Example to list all vendor passthru methods
   131  
   132  	methods, err := nodes.GetVendorPassthruMethods(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8").Extract()
   133  	if err != nil {
   134  		panic(err)
   135  	}
   136  
   137  Example to list all subscriptions
   138  
   139  	method := nodes.CallVendorPassthruOpts{
   140  		Method: "get_all_subscriptions",
   141  	}
   142  	allSubscriptions, err := nodes.GetAllSubscriptions(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8", method).Extract()
   143  	if err != nil {
   144  		panic(err)
   145  	}
   146  
   147  Example to get a subscription
   148  
   149  	method := nodes.CallVendorPassthruOpts{
   150  		Method: "get_subscription",
   151  	}
   152  	subscriptionOpt := nodes.GetSubscriptionOpts{
   153  		Id:     "subscription id",
   154  	}
   155  
   156  	subscription, err := nodes.GetSubscription(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8", method, subscriptionOpt).Extract()
   157  	if err != nil {
   158  		panic(err)
   159  	}
   160  
   161  Example to delete a subscription
   162  
   163  	method := nodes.CallVendorPassthruOpts{
   164  		Method: "delete_subscription",
   165  	}
   166  	subscriptionDeleteOpt := nodes.DeleteSubscriptionOpts{
   167  		Id: "subscription id",
   168  	}
   169  
   170  	err := nodes.DeleteSubscription(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8", method, subscriptionDeleteOpt).ExtractErr()
   171  	if err != nil {
   172  		panic(err)
   173  	}
   174  
   175  Example to create a subscription
   176  
   177  	method := nodes.CallVendorPassthruOpts{
   178  		Method: "create_subscription",
   179  	}
   180  	subscriptionCreateOpt := nodes.CreateSubscriptionOpts{
   181  		Destination: "https://subscription_destination_url"
   182  		Context:     "MyContext",
   183  		Protocol:    "Redfish",
   184  		EventTypes:  ["Alert"],
   185  		HttpHeaders: [{"Key1":"Value1"}, {"Key2":"Value2"}],
   186  	}
   187  
   188  	newSubscription, err := nodes.CreateSubscription(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8", method, subscriptionCreateOpt).Extract()
   189  	if err != nil {
   190  		panic(err)
   191  	}
   192  */
   193  package nodes