Skip to content

Commit

Permalink
Added support for the is_public parameter for flavors. Added support …
Browse files Browse the repository at this point in the history
…to adding and removing access rules for flavors.
  • Loading branch information
skipworkgh committed Jan 19, 2021
1 parent df65a55 commit d7e7c7a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Common/Api/AbstractParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,13 @@ public function allProjects(): array
'description' => '(Admin only) Lists server groups for all projects.',
];
}

public function tenant(): array
{
return [
'type' => self::STRING_TYPE,
'location' => self::JSON,
'description' => 'The UUID of the tenant in a multi-tenancy cloud.',
];
}
}
27 changes: 27 additions & 0 deletions src/Compute/v2/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function postFlavors(): array
'vcpus' => $this->params->flavorVcpus(),
'swap' => $this->params->flavorSwap(),
'disk' => $this->params->flavorDisk(),
'is_public' => $this->params->flavorIsPublic(),
],
];
}
Expand All @@ -86,6 +87,32 @@ public function deleteFlavor(): array
];
}

public function addFlavorAccessToTenant(): array
{
return [
'method' => 'POST',
'path' => 'flavors/{id}/action',
'jsonKey' => 'addTenantAccess',
'params' => [
'id' => $this->params->idPath(),
'tenant' => $this->params->tenant(),
],
];
}

public function removeFlavorAccessFromTenant(): array
{
return [
'method' => 'POST',
'path' => 'flavors/{id}/action',
'jsonKey' => 'removeTenantAccess',
'params' => [
'id' => $this->params->idPath(),
'tenant' => $this->params->tenant(),
],
];
}

public function getImages(): array
{
return [
Expand Down
32 changes: 32 additions & 0 deletions src/Compute/v2/Models/Flavor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ class Flavor extends OperatorResource implements Listable, Retrievable, Creatabl

/** @var array */
public $links;
/**
* @var bool
*/
public $is_public;

protected $resourceKey = 'flavor';
protected $resourcesKey = 'flavors';

protected $aliases = [
'os-flavor-access:is_public' => 'is_public',
];

/**
* {@inheritdoc}
*/
Expand All @@ -67,4 +75,28 @@ public function delete()
{
$this->execute($this->api->deleteFlavor(), ['id' => (string) $this->id]);
}

/**
* Creates an access rule to allow the usage of the current flavor in the given project uuid.
*
* @see https://docs.openstack.org/api-ref/compute/?expanded=add-flavor-access-to-tenant-addtenantaccess-action-detail#add-flavor-access-to-tenant-addtenantaccess-action
* @param string $project_uuid
*/
public function addAccessToProject(string $project_uuid)
{
$userValues = array_merge($this->getAttrs(['id']), ['tenant' => $project_uuid]);
$this->execute($this->api->addFlavorAccessToTenant(), $userValues);
}

/**
* Removes access to the current flavor from the given project uuid.
*
* @see https://docs.openstack.org/api-ref/compute/?expanded=remove-flavor-access-from-tenant-removetenantaccess-action-detail#remove-flavor-access-from-tenant-removetenantaccess-action
* @param string $project_uuid
*/
public function removeAccessFromProject(string $project_uuid)
{
$userValues = array_merge($this->getAttrs(['id']), ['tenant' => $project_uuid]);
$this->execute($this->api->removeFlavorAccessFromTenant(), $userValues);
}
}
10 changes: 10 additions & 0 deletions src/Compute/v2/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,16 @@ public function flavorSwap(): array
];
}

public function flavorIsPublic(): array
{
return [
'type' => self::BOOL_TYPE,
'sentAs' => 'os-flavor-access:is_public',
'location' => self::JSON,
'description' => 'Whether the flavor is public (available to all projects) or scoped to a set of projects. Default is True if not specified.',
];
}

public function volumeId(): array
{
return [
Expand Down

0 comments on commit d7e7c7a

Please sign in to comment.