VMware {code} Community
pjudson
Contributor
Contributor
Jump to solution

How to tell if a host is in maintenance mode

Is there a way using the SDK to tell if a host is in maintanence mode?

Thanks,

Paul

Reply
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

Using the vi sdk, you can get a reference to a managed object of a host. On this mo, fetch the data object runtime. This runtime data object has a property inMaintenanceMode which is a boolean value which lets you know whether the host is in maintenance mode or not.

e.g.

my $host = Vim::find_entity_view( view_type => 'HostSystem' );

print $host->runtime->inMaintenanceMode

Though while entering the maintenance mode, this boolean will not be set

and can be seen through the tasklist.

The following code snippet can be used to list the recent tasks.

my $content = Vim::get_service_content();

my $taskmgr_view = Vim::get_view(mo_ref => $content->taskManager);

my $recent_views =

Vim::get_views(mo_ref_array => $taskmgr_view->recentTask);

foreach (@$recent_views) {

my $name =$_->info->name;

my $state =$_->info->state->val;

print "\n Name of the Operation -Task" .$name;

print "\n State of the Task " .$state;

}

Using get_view, above, a managed object reference to a taskManager can be fetched from the service content. The task manager allows to get a managed object reference array of recent tasks.

Recent Tasks will list the tasks that completed recently, are currently running, or are queued to run. It contains only tasks visible to the client. Visibility depends on the client having permissions to access the task's managed entity. This will allow you to find if the enterenterMaintenanceMode task is running on a machine.

View solution in original post

Reply
0 Kudos
1 Reply
admin
Immortal
Immortal
Jump to solution

Using the vi sdk, you can get a reference to a managed object of a host. On this mo, fetch the data object runtime. This runtime data object has a property inMaintenanceMode which is a boolean value which lets you know whether the host is in maintenance mode or not.

e.g.

my $host = Vim::find_entity_view( view_type => 'HostSystem' );

print $host->runtime->inMaintenanceMode

Though while entering the maintenance mode, this boolean will not be set

and can be seen through the tasklist.

The following code snippet can be used to list the recent tasks.

my $content = Vim::get_service_content();

my $taskmgr_view = Vim::get_view(mo_ref => $content->taskManager);

my $recent_views =

Vim::get_views(mo_ref_array => $taskmgr_view->recentTask);

foreach (@$recent_views) {

my $name =$_->info->name;

my $state =$_->info->state->val;

print "\n Name of the Operation -Task" .$name;

print "\n State of the Task " .$state;

}

Using get_view, above, a managed object reference to a taskManager can be fetched from the service content. The task manager allows to get a managed object reference array of recent tasks.

Recent Tasks will list the tasks that completed recently, are currently running, or are queued to run. It contains only tasks visible to the client. Visibility depends on the client having permissions to access the task's managed entity. This will allow you to find if the enterenterMaintenanceMode task is running on a machine.

Reply
0 Kudos