Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Conversation

KevinPike
Copy link
Contributor

This pull request changes server Personality from []byte to []map[string]string, where each map is expected to contain path and base64 encoded contents.

@mdarby
Copy link

mdarby commented Apr 10, 2015

@jrperritt could you please review?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's fixed to be only path and contents, maybe we can have a Personality struct:

type Personality struct {
    Path string
    Contents string
}

and then have the field definition in the CreateOpts (and the like) be
Personality []Personality

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Perhaps Contents could be []byte and base64 encoded on Create and Rebuild, similar to how UserData is base64 encoded on Create.

type Personality struct {
    Path string
    Contents []byte
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jrperritt
Copy link
Contributor

@KevinPike Great catch. Just one suggestion above.

@KevinPike
Copy link
Contributor Author

I've tested this with Ubuntu and it works. However, I haven't had luck with Windows.

This post uses personality with a file path "C:\\cloud-automation\\bootstrap.cmd" to create a Windows server and it works.

I don't think it's working on Windows because in Go "C:\\cloud-automation\\bootstrap.cmd" serializes to "C:\\cloud-automation\\bootstrap.cmd". In Python, it serializes to "C:\cloud-automation\bootstrap.cmd". Any thoughts?

@jrperritt
Copy link
Contributor

I don't know much (read: anything) about Windows environments, but maybe you can use a forward-slash instead? For example, "C:/cloud-automation/bootstrap.cmd".

@KevinPike
Copy link
Contributor Author

It turns out that "C:\\cloud-automation\\bootstrap.cmd" is a valid path and the file will be created when using personality. I was using "C:\\cloud-automation\\bootstrap.ps1" which did not work, interestingly.

I updated Personality to marshal using MarshalJSON.

I've tested this on Ubuntu 14.04 and Windows Server 2012.

@KevinPike KevinPike changed the title [wip] Server personality Server personality Apr 21, 2015
Kevin Pike added 2 commits April 23, 2015 17:14
…o personality

Conflicts:
	openstack/compute/v2/servers/requests_test.go
Conflicts:
	openstack/compute/v2/servers/requests_test.go
@KevinPike
Copy link
Contributor Author

Ready for review

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intended use case of the method? It seems like the base64 encoding process should go in the ToServerCreateMap method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file base64 encode process is used by ToServerCreateMap and ToServerRebuildMap. Having File implement MarshalJSON seemed like a good way to reduce putting the encode logic in two places and have a File know how to marshal itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see; it's implementing the Marshaler interface. Can you add a comment above File mentioning that? Something like: "File implements the json.Marshaler interface, so when a Create or Rebuild operation is requested, json.Marshal will call File's MarshalJSON method." The only reason for explicitness is because I don't think we have this anywhere else. Also, could you add a Personality field to the acceptance test that creates a server?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! 👍

@jrperritt
Copy link
Contributor

It looks like the unit tests are failing. From Travis:
FAIL github.com/rackspace/gophercloud/openstack/compute/v2/servers [build failed]

@KevinPike
Copy link
Contributor Author

There we go. Thank you for the heads up

@jrperritt
Copy link
Contributor

Looks good. Thank you for the PR 😄

🚀

jrperritt added a commit that referenced this pull request May 6, 2015
@jrperritt jrperritt merged commit 9ad4137 into rackspace:master May 6, 2015
@coveralls
Copy link

Coverage Status

Coverage increased (+7.3%) to 94.824% when pulling 4d6c6e7 on doubledutch:personality into f3ced00 on rackspace:master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants