Example #1
0
//TestNetConfigAddAllDHCP - verify we can convert a servers interfaces to dhcp
func TestNetConfigAddAllDHCP(t *testing.T) {
	var (
		d *ICSPTest
		c *ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		serialNumber := d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
		s, err := c.GetServerBySerialNumber(serialNumber) // fake serial number
		assert.NoError(t, err, "should GetServerBySerialNumber -> %s, %+v", err, s)

		err = GetNetConfigTestData()
		assert.NoError(t, err, "should GetNetConfigTestData -> %s", err)

		var emptyconfig utils.Nstring
		emptyconfig.Nil()
		n.AddAllDHCP(s.Interfaces, false, emptyconfig)
		for _, neti := range n.Interfaces {
			assert.True(t, neti.DHCPv4, fmt.Sprintf("Should have interface, %s, dhcpv4 enabled", neti.MACAddr))
			assert.False(t, neti.IPv6Autoconfig, "Should have ipv6 auto config as false")
		}
	}
}
Example #2
0
// TODO TestSetStaticInterface - verify we can set one of the servers interface to static
// TesttoJSON - verify we can return a json string of the NetConfig object
func TestToJSON(t *testing.T) {
	var (
		d *ICSPTest
		c *ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		serialNumber := d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
		s, err := c.GetServerBySerialNumber(serialNumber) // fake serial number
		assert.NoError(t, err, "should GetServerBySerialNumber -> %s, %+v", err, s)

		err = GetNetConfigTestData()
		assert.NoError(t, err, "should GetNetConfigTestData -> %s", err)

		var emptyconfig utils.Nstring
		emptyconfig.Nil()
		n.AddAllDHCP(s.Interfaces, false, emptyconfig)
		data, err := n.toJSON()
		assert.NoError(t, err, "Should convert object to json, %s", err)
		log.Infof("n JSON -> %s", data)
		assert.True(t, len(data) > 0, "Should have some data")
	}
}
Example #3
0
// TestNetConfigSave - save netconfig to hpsa_netconfig
func TestNetConfigSave(t *testing.T) {
	var (
		d *ICSPTest
		c *ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		serialNumber := d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
		s, err := c.GetServerBySerialNumber(serialNumber) // fake serial number
		assert.NoError(t, err, "should GetServerBySerialNumber -> %s, %+v", err, s)

		err = GetNetConfigTestData()
		assert.NoError(t, err, "should GetNetConfigTestData -> %s", err)

		var emptyconfig utils.Nstring
		emptyconfig.Nil()
		n.AddAllDHCP(s.Interfaces, false, emptyconfig)
		s, err = n.Save(s)
		assert.NoError(t, err, "should Save -> %s, %+v", err, s)
		// place those strings into custom attributes
		_, err = c.SaveServer(s)
		assert.NoError(t, err, "should SaveServer -> %s, %+v", err, s)
	}
}
// get available server
// blades = rest_api(:oneview, :get, "/rest/server-hardware?sort=name:asc&filter=serverHardwareTypeUri='#{server_hardware_type_uri}'&filter=serverGroupUri='#{enclosure_group_uri}'")
func (c *OVClient) GetAvailableHardware(hardwaretype_uri utils.Nstring, servergroup_uri utils.Nstring) (hw ServerHardware, err error) {
	var (
		hwlist ServerHardwareList
		f      = []string{"serverHardwareTypeUri='" + hardwaretype_uri.String() + "'",
			"serverGroupUri='" + servergroup_uri.String() + "'"}
	)
	if hwlist, err = c.GetServerHardwareList(f, "name:desc"); err != nil {
		return hw, err
	}
	if !(len(hwlist.Members) > 0) {
		return hw, errors.New("Error! No available blades that are compatible with the server profile!")
	}

	// pick an available blade
	for _, blade := range hwlist.Members {
		if H_NOPROFILE_APPLIED.Equal(blade.State) {
			hw = blade
			break
		}
	}
	if hw.Name == "" {
		return hw, errors.New("No more blades are available for provisioning!")
	}
	return hw, nil
}
func (c *ICSPClient) GetBuildPlanByUri(uri utils.Nstring) (OSDBuildPlan, error) {

	var bldplan OSDBuildPlan
	// grab the target
	data, err := c.RestAPICall(rest.GET, uri.String(), nil)
	if err != nil {
		return bldplan, err
	}
	log.Debugf("GetBuildPlan %s", data)
	if err := json.Unmarshal([]byte(data), &bldplan); err != nil {
		return bldplan, err
	}

	return bldplan, nil
}
func (c *OVClient) GetEnclosureGroupByUri(uri utils.Nstring) (EnclosureGroup, error) {
	var (
		enclosureGroup EnclosureGroup
	)
	// refresh login
	c.RefreshLogin()
	c.SetAuthHeaderOptions(c.GetAuthHeaderMap())
	data, err := c.RestAPICall(rest.GET, uri.String(), nil)
	if err != nil {
		return enclosureGroup, err
	}
	log.Debugf("GetEnclosureGroup %s", data)
	if err := json.Unmarshal([]byte(data), &enclosureGroup); err != nil {
		return enclosureGroup, err
	}
	return enclosureGroup, nil
}
Example #7
0
// TestNewNetConfig - verify we can create an empty netconfig type
func TestNewNetConfig(t *testing.T) {
	var emptyconfig utils.Nstring
	emptyconfig.Nil()
	// TODO: determine configuration options for network customization
	n = NewNetConfig(emptyconfig, //s.HostName,
		emptyconfig, // workgroup utils.Nstring,
		emptyconfig, // domain utils.Nstring,
		emptyconfig, // winslist utils.Nstring,
		emptyconfig, // dnsnamelist utils.Nstring,
		emptyconfig) // dnssearchlist utils.Nstring)
	assert.Equal(t, "", n.Hostname, "should have empty hostname")
	assert.Equal(t, "", n.Workgroup, "should have empty workgroup")
	assert.Equal(t, "", n.Domain, "should have empty domain")
	assert.Equal(t, emptyconfig, n.WINSList, "should have empty winslist")
	assert.Equal(t, emptyconfig, n.DNSNameList, "should have empty dnsnamelist")
	assert.Equal(t, emptyconfig, n.DNSSearchList, "should have empty dnssearchlist")
}
func (c *OVClient) GetInterconnectTypeByUri(uri utils.Nstring) (InterconnectType, error) {
	var (
		interconnectType InterconnectType
	)
	// refresh login
	c.RefreshLogin()
	c.SetAuthHeaderOptions(c.GetAuthHeaderMap())
	data, err := c.RestAPICall(rest.GET, uri.String(), nil)
	if err != nil {
		return interconnectType, err
	}
	log.Debugf("GetInterconnectType %s", data)
	if err := json.Unmarshal([]byte(data), &interconnectType); err != nil {
		return interconnectType, err
	}
	return interconnectType, nil
}
Example #9
0
// GetProfileByURI - get the profile from a uri
func (c *OVClient) GetProfileByURI(uri utils.Nstring) (ServerProfile, error) {
	var (
		profile ServerProfile
	)

	// refresh login
	c.RefreshLogin()
	c.SetAuthHeaderOptions(c.GetAuthHeaderMap())
	data, err := c.RestAPICall(rest.GET, uri.String(), nil)
	if err != nil {
		return profile, err
	}

	log.Debugf("GetProfileByURI %s", data)
	if err := json.Unmarshal([]byte(data), &profile); err != nil {
		return profile, err
	}
	return profile, nil
}
// get an os deployment plan with uri
func (c *OVClient) GetOSDeploymentPlan(uri utils.Nstring) (OSDeploymentPlan, error) {

	var osDeploymentPlan OSDeploymentPlan
	// refresh login

	c.RefreshLogin()
	c.SetAuthHeaderOptions(c.GetAuthHeaderMap())

	// rest call
	data, err := c.RestAPICall(rest.GET, uri.String(), nil)
	if err != nil {
		return osDeploymentPlan, err
	}

	log.Debugf("GetOSDeploymentPlan %s", data)
	if err := json.Unmarshal([]byte(data), &osDeploymentPlan); err != nil {
		return osDeploymentPlan, err
	}
	return osDeploymentPlan, nil
}
Example #11
0
// get a server hardware with uri
func (c *OVClient) GetServerHardware(uri utils.Nstring) (ServerHardware, error) {

	var hardware ServerHardware
	// refresh login
	c.RefreshLogin()
	c.SetAuthHeaderOptions(c.GetAuthHeaderMap())

	// rest call
	data, err := c.RestAPICall(rest.GET, uri.String(), nil)
	if err != nil {
		return hardware, err
	}

	log.Debugf("GetServerHardware %s", data)
	if err := json.Unmarshal([]byte(data), &hardware); err != nil {
		return hardware, err
	}
	hardware.Client = c
	return hardware, nil
}
// NewNetConfigInterface - creates an interface object for NetConfig
func (n *NetConfig) NewNetConfigInterface(
	enable bool,
	macaddr string,
	isdhcp bool,
	isipv6 bool,
	ipv6gateway utils.Nstring, // ipv6 gateway, required with isipv6 is true
	ipv4gateway utils.Nstring, // ipv4 gateway, required when isdhcp is false
	staticnets utils.Nstring, // comma seperated list of ip's, required when isdhcp is false
	name utils.Nstring, // optional name
	wins utils.Nstring, // comma seperated list of wins servers
	dnsservers utils.Nstring, // comma seperated list of dns servers
	dnssearch utils.Nstring,
	vlandid int) NetConfigInterface { // comma seperated list of dns search

	var inetconfig NetConfigInterface

	inetconfig = NetConfigInterface{
		Enabled:        enable,
		MACAddr:        macaddr,
		DHCPv4:         isdhcp,
		IPv6Autoconfig: isipv6,
		VlanID:         vlandid,
	}
	if macaddr == "" {
		log.Error("Network configuration (NetConfigInterface) requires a MAC Address to create a new interface object.")
	}
	if isipv6 {
		if ipv6gateway.IsNil() {
			log.Error("Gateway for ipv6 is required, configure IPv6Gateway")
		}
		inetconfig.IPv6Gateway = ipv6gateway.String()
	}
	if !isdhcp {
		if ipv4gateway.IsNil() {
			log.Error("Static ipv4 configuration requires a gateway configured (IPv4Gateway)")
		}
		inetconfig.IPv4Gateway = ipv4gateway.String()
		if staticnets.IsNil() {
			log.Error("Static ipv4 configuration requires static network list")
		}
		inetconfig.StaticNetworks = strings.Split(staticnets.String(), SplitSep)
	}
	if !name.IsNil() {
		inetconfig.Name = name.String()
	}
	if !wins.IsNil() {
		inetconfig.WINSServers = strings.Split(wins.String(), SplitSep)
	}
	if !dnsservers.IsNil() {
		inetconfig.DNSServers = strings.Split(dnsservers.String(), SplitSep)
	}
	if !dnssearch.IsNil() {
		inetconfig.DNSSearch = strings.Split(dnssearch.String(), SplitSep)
	}
	return inetconfig
}
// NewNetConfig - create a new netconfig object without interfaces
func NewNetConfig(
	hostname utils.Nstring,
	workgroup utils.Nstring,
	domain utils.Nstring,
	winslist utils.Nstring,
	dnsnamelist utils.Nstring,
	dnssearchlist utils.Nstring) NetConfig {

	var netconfig NetConfig
	netconfig = NetConfig{
		WINSList:      winslist,
		DNSNameList:   dnsnamelist,
		DNSSearchList: dnssearchlist,
	}
	if !hostname.IsNil() {
		netconfig.Hostname = hostname.String()
	}
	if !workgroup.IsNil() {
		netconfig.Workgroup = workgroup.String()
	}
	if !domain.IsNil() {
		netconfig.Domain = domain.String()
	}
	return netconfig
}
Example #14
0
// PostApplyDeploymentJobs - post deployment task to update custom attributes with
// results of a job task that was executed on the server
func (c *ICSPClient) PostApplyDeploymentJobs(jt *JobTask, s Server, properties []string) error {
	// look at jobResultLogDetails, parse *=* strings
	job, err := c.GetJob(jt.JobURI)
	if err != nil {
		return err
	}
	// parses the provisioning log to set any attributes from output of the log
	for _, result := range job.JobResult {
		for _, line := range strings.Split(result.JobResultLogDetails, "\n") {
			r := regexp.MustCompile("(.*)=(.*)")
			if r.FindString(line) != "" {
				for _, property := range properties {
					a := r.FindStringSubmatch(line)
					if len(a) >= 3 && property == a[1] {
						s.SetCustomAttribute(a[1], "server", a[2])
					}
				}
			}
		}
	}

	// do netconfiguration for all interfaces on server s
	var netconfig NetConfig
	var emptyconfig utils.Nstring
	emptyconfig.Nil()
	// TODO: determine configuration options for network customization
	netconfig = NewNetConfig(emptyconfig, //s.HostName,
		emptyconfig, // workgroup utils.Nstring,
		emptyconfig, // domain utils.Nstring,
		emptyconfig, // winslist utils.Nstring,
		emptyconfig, // dnsnamelist utils.Nstring,
		emptyconfig) // dnssearchlist utils.Nstring)
	netconfig.AddAllDHCP(s.Interfaces, false, emptyconfig) // TODO: could use a option for ipv6
	s, err = netconfig.Save(s)
	if err != nil {
		return err
	}
	// place those strings into custom attributes
	s, err = c.SaveServer(s)
	if err != nil {
		return err
	}

	// apply os build plan customizations for netconfig
	buildplans := make([]string, 1)
	buildplans[0] = "ProLiant SW - Post Install Network Personalization"

	_, err = c.ApplyDeploymentJobs(buildplans, netconfig.GetPersonalityData(), s)
	if err != nil {
		return err
	}

	// update public_interface
	s, err = s.ReloadFull(c)
	if err != nil {
		return err
	}

	// get the existing mac address for public interface
	inet, err := s.GetPublicInterface()
	if err != nil {
		return err
	}
	pubinet, err := s.GetInterfaceFromMac(inet.MACAddr)
	// re-save interface to public_interface
	s, err = c.UpdatePublicInterfaceAttributes(s, pubinet)
	log.Debugf("Server settings s after post deploy -> %+v", s)
	return err
}