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

Add commands to get index of booted, pending and previous deployments #3144

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions man/ostree-admin-status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,33 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>-b, --booted-index</option></term>

<listitem><para>
Print the index of the booted deployment. If we are not in a booted
OSTree system, an error is returned.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>-p, --pending-index</option></term>

<listitem><para>
Print the index of the pending deployment. If we are not in a booted
OSTree system, an error is returned.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>-r, --rollback-index</option></term>

<listitem><para>
Print the index of the rollback deployment. If we are not in a booted
OSTree system, an error is returned.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>-v, --verbose</option></term>

Expand Down
37 changes: 37 additions & 0 deletions src/ostree/ot-admin-builtin-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
static gboolean opt_verify;
static gboolean opt_skip_signatures;
static gboolean opt_is_default;
static gboolean opt_booted_index;
static gboolean opt_pending_index;
static gboolean opt_rollback_index;

static GOptionEntry options[]
= { { "verify", 'V', 0, G_OPTION_ARG_NONE, &opt_verify, "Print the commit verification status",
Expand All @@ -40,6 +43,12 @@ static GOptionEntry options[]
{ "is-default", 'D', 0, G_OPTION_ARG_NONE, &opt_is_default,
"Output \"default\" if booted into the default deployment, otherwise \"not-default\"",
NULL },
{ "booted-index", 'b', 0, G_OPTION_ARG_NONE, &opt_booted_index,
"Print the index of the booted deployment", NULL },
{ "pending-index", 'p', 0, G_OPTION_ARG_NONE, &opt_pending_index,
"Print the index of the pending deployment", NULL },
{ "rollback-index", 'r', 0, G_OPTION_ARG_NONE, &opt_rollback_index,
"Print the index of the rollback deployment", NULL },
{ NULL } };
static gboolean
deployment_print_status (OstreeSysroot *sysroot, OstreeRepo *repo, OstreeDeployment *deployment,
Expand Down Expand Up @@ -182,6 +191,22 @@ deployment_print_status (OstreeSysroot *sysroot, OstreeRepo *repo, OstreeDeploym
return TRUE;
}

static gboolean
find_deployment_index (const OstreeDeployment *target_deployment, const GPtrArray *deployments)
{
for (guint i = 0; i < deployments->len; ++i)
{
const OstreeDeployment *deployment = deployments->pdata[i];
if (deployment == target_deployment)
{
g_print ("%d\n", i);
return TRUE;
}
}

return FALSE;
}

gboolean
ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocation,
GCancellable *cancellable, GError **error)
Expand Down Expand Up @@ -218,6 +243,18 @@ ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocat
{
g_print ("No deployments.\n");
}
else if (opt_booted_index)
{
return find_deployment_index (booted_deployment, deployments);
}
else if (opt_pending_index)
{
return find_deployment_index (pending_deployment, deployments);
}
else if (opt_rollback_index)
{
return find_deployment_index (rollback_deployment, deployments);
}
else
{
for (guint i = 0; i < deployments->len; i++)
Expand Down
Loading