Update OpenStack run and push support

This commit updates the support for pushing images into OpenStack by
inheriting environment variables for endpoint and authentication
information, when available.

It also attempts to make the `openstack run` support more consistent
with other providers (specifically GCP and AWS), i.e just take the name
of the image as the argument and launch an instance using that.

Finally, it also updates the relevant documentation for OpenStack
support.

Signed-off-by: Nick Jones <nick@dischord.org>
This commit is contained in:
Nick Jones
2017-08-02 22:26:28 +01:00
parent 550bf41d0b
commit f65a4e803d
3 changed files with 102 additions and 46 deletions

View File

@@ -25,13 +25,12 @@ func pushOpenstack(args []string) {
fmt.Printf("Options:\n\n")
flags.PrintDefaults()
}
authurl := flags.String("authurl", "", "The URL of the OpenStack identity service, i.e https://keystone.example.com:5000/v3")
usernameFlag := flags.String("username", "", "Username with permissions to upload image")
passwordFlag := flags.String("password", "", "Password for the Username")
projectName := flags.String("project", "", "Name of the Project (aka Tenant) to be used")
userDomainFlag := flags.String("domain", "Default", "Domain name")
authurlFlag := flags.String("authurl", "", "The URL of the OpenStack identity service, i.e https://keystone.example.com:5000/v3")
imageName := flags.String("img-name", "", "A unique name for the image, if blank the filename will be used")
passwordFlag := flags.String("password", "", "Password for the specified username")
projectNameFlag := flags.String("project", "", "Name of the Project (aka Tenant) to be used")
userDomainFlag := flags.String("domain", "Default", "Domain name")
usernameFlag := flags.String("username", "", "Username with permissions to upload image")
if err := flags.Parse(args); err != nil {
log.Fatal("Unable to parse args")
@@ -47,12 +46,18 @@ func pushOpenstack(args []string) {
// Check that the file both exists, and can be read
checkFile(filePath)
authurl := getStringValue(authurlVar, *authurlFlag, "")
password := getStringValue(passwordVar, *passwordFlag, "")
projectName := getStringValue(projectNameVar, *projectNameFlag, "")
userDomain := getStringValue(userDomainVar, *userDomainFlag, "")
username := getStringValue(usernameVar, *usernameFlag, "")
authOpts := gophercloud.AuthOptions{
IdentityEndpoint: *authurl,
Username: *usernameFlag,
Password: *passwordFlag,
DomainName: *userDomainFlag,
TenantName: *projectName,
DomainName: userDomain,
IdentityEndpoint: authurl,
Password: password,
TenantName: projectName,
Username: username,
}
provider, err := openstack.AuthenticatedClient(authOpts)
if err != nil {

View File

@@ -25,35 +25,49 @@ func runOpenStack(args []string) {
flags := flag.NewFlagSet("openstack", flag.ExitOnError)
invoked := filepath.Base(os.Args[0])
flags.Usage = func() {
fmt.Printf("USAGE: %s run openstack [options]\n\n", invoked)
fmt.Printf("USAGE: %s run openstack [options] [name]\n\n", invoked)
fmt.Printf("'name' is the name of an OpenStack image that has already been\n")
fmt.Printf(" uploaded using 'linuxkit push'\n\n")
fmt.Printf("Options:\n\n")
flags.PrintDefaults()
}
authurlFlag := flags.String("authurl", "", "The URL of the OpenStack identity service, i.e https://keystone.example.com:5000/v3")
usernameFlag := flags.String("username", "", "Username with permissions to create an instance")
flavorName := flags.String("flavor", defaultOSFlavor, "Instance size (flavor)")
instanceName := flags.String("instancename", "", "Name of instance. Defaults to the name of the image if not specified")
networkID := flags.String("network", "", "The ID of the network to attach the instance to")
passwordFlag := flags.String("password", "", "Password for the specified username")
projectNameFlag := flags.String("project", "", "Name of the Project (aka Tenant) to be used")
userDomainFlag := flags.String("domain", "Default", "Domain name")
imageID := flags.String("img-ID", "", "The ID of the image to boot the instance from")
networkID := flags.String("network", "", "The ID of the network to attach the instance to")
flavorName := flags.String("flavor", defaultOSFlavor, "Instance size (flavor)")
name := flags.String("name", "", "Name of the instance")
usernameFlag := flags.String("username", "", "Username with permissions to create an instance")
if err := flags.Parse(args); err != nil {
log.Fatal("Unable to parse args")
}
remArgs := flags.Args()
if len(remArgs) == 0 {
fmt.Printf("Please specify the name of the image to boot\n")
flags.Usage()
os.Exit(1)
}
name := remArgs[0]
if *instanceName == "" {
*instanceName = name
}
authurl := getStringValue(authurlVar, *authurlFlag, "")
username := getStringValue(usernameVar, *usernameFlag, "")
password := getStringValue(passwordVar, *passwordFlag, "")
projectName := getStringValue(projectNameVar, *projectNameFlag, "")
userDomain := getStringValue(userDomainVar, *userDomainFlag, "")
username := getStringValue(usernameVar, *usernameFlag, "")
authOpts := gophercloud.AuthOptions{
IdentityEndpoint: authurl,
Username: username,
Password: password,
DomainName: userDomain,
IdentityEndpoint: authurl,
Password: password,
TenantName: projectName,
Username: username,
}
provider, err := openstack.AuthenticatedClient(authOpts)
if err != nil {
@@ -71,8 +85,8 @@ func runOpenStack(args []string) {
serverOpts := &servers.CreateOpts{
FlavorName: *flavorName,
ImageRef: *imageID,
Name: *name,
ImageName: name,
Name: *instanceName,
Networks: []servers.Network{network},
ServiceClient: client,
}