<commit_before>package openstack

import (
	"context"
	"fmt"
	"io/ioutil"
	"log"

	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
	"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
	"github.com/hashicorp/packer/helper/multistep"
	"github.com/hashicorp/packer/packer"
)

type StepRunSourceServer struct {
	Name             string
	SourceImage      string
	SourceImageName  string
	SecurityGroups   []string
	Networks         []string
	Ports            []string
	AvailabilityZone string
	UserData         string
	UserDataFile     string
	ConfigDrive      bool
	InstanceMetadata map[string]string
	server           *servers.Server
}

func (s *StepRunSourceServer) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
	config := state.Get("config").(Config)
	flavor := state.Get("flavor_id").(string)
	ui := state.Get("ui").(packer.Ui)

	// We need the v2 compute client
	computeClient, err := config.computeV2Client()
	if err != nil {
		err = fmt.Errorf("Error initializing compute client: %s", err)
		state.Put("error", err)
		return multistep.ActionHalt
	}

	networks := make([]servers.Network, len(s.Networks)+len(s.Ports))
	i := 0
	if len(s.Ports) > 0 {
		for i = 0; i < len(s.Ports); i++ {
			networks[i].Port = s.Ports[i]
		}
	}
	if len(s.Networks) > 0 {
		for i = len(s.Ports); i < len(networks); i++ {
			networks[i].UUID = s.Networks[i]
		}
	}<commit_msg>Simplified loop code<commit_after>package openstack

import (
	"context"
	"fmt"
	"io/ioutil"
	"log"

	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
	"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
	"github.com/hashicorp/packer/helper/multistep"
	"github.com/hashicorp/packer/packer"
)

type StepRunSourceServer struct {
	Name             string
	SourceImage      string
	SourceImageName  string
	SecurityGroups   []string
	Networks         []string
	Ports            []string
	AvailabilityZone string
	UserData         string
	UserDataFile     string
	ConfigDrive      bool
	InstanceMetadata map[string]string
	server           *servers.Server
}

func (s *StepRunSourceServer) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
	config := state.Get("config").(Config)
	flavor := state.Get("flavor_id").(string)
	ui := state.Get("ui").(packer.Ui)

	// We need the v2 compute client
	computeClient, err := config.computeV2Client()
	if err != nil {
		err = fmt.Errorf("Error initializing compute client: %s", err)
		state.Put("error", err)
		return multistep.ActionHalt
	}

	networks := make([]servers.Network, len(s.Networks)+len(s.Ports))
	i := 0
	for ; i < len(s.Ports); i++ {
		networks[i].Port = s.Ports[i]
	}
	for ; i < len(networks); i++ {
		networks[i].UUID = s.Networks[i]
	}
{'fraction_non_alphanumeric': 0.13350125944584382, 'fraction_numerical': 0.004677941705649514, 'mean_word_length': 3.664429530201342, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '5820459', 'n_tokens_mistral': 1023, 'n_tokens_neox': 998, 'n_words': 196}