Ejemplo n.º 1
0
func (c *Client) BootComplete(serial string, host hostmgr.Host) error {
	data, err := json.Marshal(host)

	if err != nil {
		return err
	}

	resp, err := httputil.Put(fmt.Sprintf("%s://%s:%d/admin/host/%s/boot_complete", c.Scheme, c.Host, c.Port, serial), "application/json", bytes.NewBuffer(data))
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	return nil
}
Ejemplo n.º 2
0
// SetIPMIAddr sets the IPMI address given by value for a node given by serial.
func (c *Client) SetIPMIAddr(serial, value string) error {
	data, err := json.Marshal(hostmgr.Host{
		IPMIAddr: net.ParseIP(value),
	})
	if err != nil {
		return err
	}

	resp, err := httputil.Put(fmt.Sprintf("%s://%s:%d/admin/host/%s/set_ipmi_addr", c.Scheme, c.Host, c.Port, serial), contentType, bytes.NewBuffer(data))
	if err != nil {
		return err
	}
	if resp.StatusCode > 399 {
		return fmt.Errorf("invalid status code '%d'", resp.StatusCode)
	}
	defer resp.Body.Close()
	return nil
}
Ejemplo n.º 3
0
// SetMetadata sets fleet metadata given by value for a node given by serial.
func (c *Client) SetMetadata(serial, value string) error {
	data, err := json.Marshal(hostmgr.Host{
		FleetMetadata: strings.Split(value, ","),
	})
	if err != nil {
		return err
	}

	resp, err := httputil.Put(fmt.Sprintf("%s://%s:%d/admin/host/%s/set_metadata", c.Scheme, c.Host, c.Port, serial), contentType, bytes.NewBuffer(data))
	if err != nil {
		return err
	}
	if resp.StatusCode > 399 {
		return fmt.Errorf("invalid status code '%d'", resp.StatusCode)
	}
	defer resp.Body.Close()
	return nil
}
Ejemplo n.º 4
0
// Override overrides a template properties such as docker_version, yochu_version, etc
func (c *Client) Override(serial, property, value string) error {
	data, err := json.Marshal(hostmgr.Host{
		Overrides: map[string]interface{}{property: value},
	})
	if err != nil {
		return err
	}

	resp, err := httputil.Put(fmt.Sprintf("%s://%s:%d/admin/host/%s/override", c.Scheme, c.Host, c.Port, serial), contentType, bytes.NewBuffer(data))
	if err != nil {
		return err
	}
	if resp.StatusCode > 399 {
		return fmt.Errorf("invalid status code '%d'", resp.StatusCode)
	}
	defer resp.Body.Close()
	return nil
}
Ejemplo n.º 5
0
// SetEtcdClusterToken sets the etcd cluster token given by value for a node given by serial.
func (c *Client) SetEtcdClusterToken(serial, value string) error {
	data, err := json.Marshal(hostmgr.Host{
		EtcdClusterToken: value,
	})
	if err != nil {
		return err
	}

	resp, err := httputil.Put(fmt.Sprintf("%s://%s:%d/admin/host/%s/set_etcd_cluster_token", c.Scheme, c.Host, c.Port, serial), contentType, bytes.NewBuffer(data))
	if err != nil {
		return err
	}
	if resp.StatusCode > 399 {
		return fmt.Errorf("invalid status code '%d'", resp.StatusCode)
	}
	defer resp.Body.Close()
	return nil
}
Ejemplo n.º 6
0
// SetCabinet sets the cabinet given by value for a node given by serial.
func (c *Client) SetCabinet(serial, value string) error {
	cabinet, err := strconv.ParseUint(value, 10, 0)
	if err != nil {
		return err
	}

	data, err := json.Marshal(hostmgr.Host{
		Cabinet: uint(cabinet),
	})
	if err != nil {
		return err
	}

	resp, err := httputil.Put(fmt.Sprintf("%s://%s:%d/admin/host/%s/set_cabinet", c.Scheme, c.Host, c.Port, serial), contentType, bytes.NewBuffer(data))
	if err != nil {
		return err
	}
	if resp.StatusCode > 399 {
		return fmt.Errorf("invalid status code '%d'", resp.StatusCode)
	}
	defer resp.Body.Close()
	return nil
}