Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable use of service ticket for datastore HTTP access by default #635

Merged
merged 2 commits into from
Dec 1, 2016

Conversation

dougm
Copy link
Member

@dougm dougm commented Dec 1, 2016

Can still be enabled by setting GOVMOMI_USE_SERVICE_TICKET=true
as a GOVC_URL query param or environment variable.

  • Only use service tickets when connected to VC

  • Add Datastore.HostContext helper for cases where datastore files
    can only be read by the host where the VM is running

  • Prefer host management IP to host inventory name

  • Add -host option to govc datastore.download and datastore.tail to optionally
    specify the host owning the lock for a VM file open for writing (e.g. vmware.log)

  • Collapse some common code code for constructing the URL

  • Use the full inventory path for the dcPath parameter (Fixes Datastore.URL(...) returns incorrect url when Datacenter is in a folder #594)

Can still be enabled by setting GOVMOMI_USE_SERVICE_TICKET=true
as a GOVC_URL query param or environment variable.

- Only use service tickets when connected to VC

- Add Datastore.HostContext helper for cases where datastore files
  can only be read by the host where the VM is running

- Prefer host management IP to host inventory name

- Add -host option to govc datastore.download and datastore.tail to optionally
  specify the host owning the lock for a VM file open for writing (e.g. vmware.log)

- Collapse some common code code for constructing the URL

- Use the full inventory path for the dcPath parameter (Fixes vmware#594)
@@ -73,6 +81,18 @@ func (cmd *download) Run(ctx context.Context, f *flag.FlagSet) error {
return err
}

var via string

Choose a reason for hiding this comment

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

Small readability note: can we move via closer to where it's used?

Copy link
Member Author

Choose a reason for hiding this comment

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

will do

@@ -39,12 +41,18 @@ func init() {
func (cmd *download) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
cmd.DatastoreFlag.Register(ctx, f)

cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
Copy link

Choose a reason for hiding this comment

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

I wonder why do we pass context and get it back?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't implement that pattern, but I believe its because some flags attach context.Value(s)

if cmd.OutputFlag.TTY {
logger := cmd.ProgressLogger("Downloading... ")
if cmd.DatastoreFlag.OutputFlag.TTY {
logger := cmd.DatastoreFlag.ProgressLogger(fmt.Sprintf("Downloading%s... ", via))
Copy link

Choose a reason for hiding this comment

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

Shouldn't it be something like ": " before %s?

Copy link
Member Author

Choose a reason for hiding this comment

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

Default message is just: "Downloading..."
If host is specified, looks like: "Downloading via esx1-host.example.com..."

}

// NewURL constructs a url.URL with the given file path for datastore access over HTTP.
func (d Datastore) NewURL(path string) *url.URL {
Copy link

Choose a reason for hiding this comment

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

Why D is not the reference?

Copy link
Member Author

Choose a reason for hiding this comment

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

In general my preference/habit is to use pointer receivers, but the existing wrappers use value.

}
var host *HostSystem

h := ctx.Value(datastoreServiceTicketHostKey)
Copy link

@vburenin vburenin Dec 1, 2016

Choose a reason for hiding this comment

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

you could just cast h in place without checking for nil: https://play.golang.org/p/T6cKj0hHM3

Copy link
Member Author

Choose a reason for hiding this comment

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

yes that'll clean this up a bit, I'll do that.

@vburenin
Copy link

vburenin commented Dec 1, 2016

I have no concerns about the correctness of this code. Things looks good to me. There are some cosmetic improvements could be made, but that is it.
LGTM

@cgtexmex
Copy link
Contributor

cgtexmex commented Dec 1, 2016

lgtm

1 similar comment
@hmahmood
Copy link

hmahmood commented Dec 1, 2016

lgtm

@@ -312,6 +318,7 @@ func (f *Finder) DatastoreList(ctx context.Context, path string) ([]*object.Data
if ref.Type == "Datastore" {
ds := object.NewDatastore(f.client, ref)
ds.InventoryPath = e.Path
ds.DatacenterPath = f.dc.InventoryPath
Copy link
Member

Choose a reason for hiding this comment

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

is dc guaranteed to be non-nil at this point?

Copy link
Member Author

Choose a reason for hiding this comment

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

The f.datastoreFolder func above takes care of checking f.dc != nil. You'd have to be using Finder without having called SetDatacenter and all inputs as absolute paths without wildcards, in which case there's no point to using Finder :)

Copy link

Choose a reason for hiding this comment

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

@dougm In one of my projects I'm using absolute path to the datastore, e.g. /MyDatacenter/datastore/vm-storage01 and use a Finder.Datastore() to get the datastore object, but now I get panics because of this.

What would be the recommended way without having to call SetDatacenter(), because that would be another parameter I need to add to my project and that's already lots of changes I need to do to adjust the code to the recent change?

Thanks,
Marin

Copy link
Member Author

Choose a reason for hiding this comment

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

@dnaeon in that case you don't need Finder, as SearchIndex.FindByInventoryPath does the job with absolute paths. But I'd be fine with adding the nil check for now. Are you using any of the Datastore upload/download methods? Those need the Datacenter ref against VC, unless you set GOVMOMI_USE_SERVICE_TICKET=true

@@ -58,6 +58,8 @@ func (e DatastoreNoSuchFileError) Error() string {

type Datastore struct {
Common

DatacenterPath string
Copy link
Member

Choose a reason for hiding this comment

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

Given everything lives in the context of a datacenter, should this move into Common eventually?

Copy link
Member Author

Choose a reason for hiding this comment

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

Started on that route initially, but opted to keep the diff a bit smaller and ideally there won't be other types that need this path. Datastore is the only type currently that uses HTTP without the vmodl.

hosts, err := d.AttachedHosts(ctx)
if err != nil {
return nil, nil, err
}

if len(hosts) == 0 {
return nil, nil, fmt.Errorf("no hosts attached to datastore %#v", d.Reference())
return u, nil, nil
Copy link
Member

Choose a reason for hiding this comment

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

comment about fallback to VC

Copy link
Member Author

Choose a reason for hiding this comment

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

will do

@hickeng
Copy link
Member

hickeng commented Dec 1, 2016

LGTM

@dougm dougm merged commit e702e18 into vmware:master Dec 1, 2016
@dougm dougm deleted the service-ticket-host branch December 1, 2016 19:12
dougm added a commit to dougm/govmomi that referenced this pull request Dec 9, 2016
PR vmware#635 assumed that Finder would not be used without having called SetDatacenter.
However, when the Datastore methods are used with absolute paths and without SetDatacenter,
would cause a panic.
dougm added a commit that referenced this pull request Dec 12, 2016
PR #635 assumed that Finder would not be used without having called SetDatacenter.
However, when the Datastore methods are used with absolute paths and without SetDatacenter,
would cause a panic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants