<commit_before>package server

import (
	"encoding/json"
	"fmt"

	bosherr "github.com/cloudfoundry/bosh-utils/errors"

	"github.com/frodenas/bosh-openstack-cpi/api"
	"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs"
	"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/schedulerhints"
	"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
)

func (i OpenStackServerService) Create(serverProps *Properties, networks Networks, registryEndpoint string) (string, error) {
	var createOpts servers.CreateOptsBuilder

	uuidStr, err := i.uuidGen.Generate()
	if err != nil {
		return "", bosherr.WrapErrorf(err, "Generating random OpenStack Server name")
	}

	serverName := fmt.Sprintf("%s-%s", openstackServerNamePrefix, uuidStr)
	userdataParams, err := i.createUserdataParams(serverName, registryEndpoint, networks)
	if err != nil {
		return "", err
	}

	configDrive := true
	if serverProps.DisableConfigDrive {
		configDrive = false
	}

	createOpts = &servers.CreateOpts{
		Name:             serverName,
		ImageRef:         serverProps.ImageID,
		FlavorRef:        serverProps.FlavorID,
		SecurityGroups:   []string{},
		UserData:         userdataParams,
		AvailabilityZone: serverProps.AvailabilityZone,
		//Networks: "",
		ConfigDrive: configDrive,
	}

	createOpts = &keypairs.CreateOptsExt{
		createOpts,
		serverProps.KeyPair,
	}

	createOpts = &schedulerhints.CreateOptsExt{
		createOpts,
		schedulerhints.SchedulerHints{
			Group:           serverProps.SchedulerHints.Group,
			DifferentHost:   serverProps.SchedulerHints.DifferentHost,
			SameHost:        serverProps.SchedulerHints.SameHost,
			Query:           serverProps.SchedulerHints.Query,
			TargetCell:      serverProps.SchedulerHints.TargetCell,
			BuildNearHostIP: serverProps.SchedulerHints.BuildNearHostIP,
		},
	}

	i.logger.Debug(openstackServerServiceLogTag, "Creating OpenStack Server with params: %#v", createOpts)
	server, err := servers.Create(i.computeService, createOpts).Extract()
	if err != nil {
		i.logger.Debug(openstackServerServiceLogTag, "Failed to create OpenStack Server: %#v", err)
		return "", api.NewVMCreationFailedError(true)
	}

	return server.ID, nil
}

func (i OpenStackServerService) CleanUp(id string) {
	err := i.Delete(id)<commit_msg>Print proper server create options<commit_after>package server

import (
	"encoding/json"
	"fmt"

	bosherr "github.com/cloudfoundry/bosh-utils/errors"

	"github.com/frodenas/bosh-openstack-cpi/api"
	"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs"
	"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/schedulerhints"
	"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
)

func (i OpenStackServerService) Create(serverProps *Properties, networks Networks, registryEndpoint string) (string, error) {
	var createOpts servers.CreateOptsBuilder

	uuidStr, err := i.uuidGen.Generate()
	if err != nil {
		return "", bosherr.WrapErrorf(err, "Generating random OpenStack Server name")
	}

	serverName := fmt.Sprintf("%s-%s", openstackServerNamePrefix, uuidStr)
	userdataParams, err := i.createUserdataParams(serverName, registryEndpoint, networks)
	if err != nil {
		return "", err
	}

	configDrive := true
	if serverProps.DisableConfigDrive {
		configDrive = false
	}

	createOpts = &servers.CreateOpts{
		Name:             serverName,
		ImageRef:         serverProps.ImageID,
		FlavorRef:        serverProps.FlavorID,
		SecurityGroups:   []string{},
		UserData:         userdataParams,
		AvailabilityZone: serverProps.AvailabilityZone,
		//Networks: "",
		ConfigDrive: configDrive,
	}

	createOpts = &keypairs.CreateOptsExt{
		createOpts,
		serverProps.KeyPair,
	}

	createOpts = &schedulerhints.CreateOptsExt{
		createOpts,
		schedulerhints.SchedulerHints{
			Group:           serverProps.SchedulerHints.Group,
			DifferentHost:   serverProps.SchedulerHints.DifferentHost,
			SameHost:        serverProps.SchedulerHints.SameHost,
			Query:           serverProps.SchedulerHints.Query,
			TargetCell:      serverProps.SchedulerHints.TargetCell,
			BuildNearHostIP: serverProps.SchedulerHints.BuildNearHostIP,
		},
	}

	serverOpts, _ := createOpts.ToServerCreateMap()
	i.logger.Debug(openstackServerServiceLogTag, "Creating OpenStack Server with params: %#v", serverOpts)
	server, err := servers.Create(i.computeService, createOpts).Extract()
	if err != nil {
		i.logger.Debug(openstackServerServiceLogTag, "Failed to create OpenStack Server: %#v", err)
		return "", api.NewVMCreationFailedError(true)
	}

	return server.ID, nil
}

func (i OpenStackServerService) CleanUp(id string) {
	err := i.Delete(id)
{'fraction_non_alphanumeric': 0.10885529157667387, 'fraction_numerical': 0.0012958963282937365, 'mean_word_length': 4.626974483596598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5626820', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1506, 'n_words': 265}