Images API¶
The ImagesAPI
client provides methods for managing Incus images.
Usage¶
from incus_sdk import Client
async with Client() as client:
# List all images
images = await client.images.list()
# Get an image by fingerprint
image = await client.images.get("abcdef123456")
# Create an image from a file
with open("image.tar.gz", "rb") as f:
image_data = f.read()
await client.images.create(
image_data=image_data,
filename="image.tar.gz",
properties={"description": "My custom image"},
wait=True
)
# Export an image to a file
await client.images.export("abcdef123456", "exported_image.tar.gz")
# Create an alias for an image
await client.images.create_alias(
name="my-image",
target="abcdef123456",
description="My custom image"
)
# Delete an image
await client.images.delete("abcdef123456", wait=True)
Class Documentation¶
API client for Incus images.
Source code in incus_sdk/api/images.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
__init__(client)
¶
Initialize a new ImagesAPI client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
APIClient
|
The base API client. |
required |
Source code in incus_sdk/api/images.py
16 17 18 19 20 21 22 23 |
|
create(image_data, filename=None, public=False, auto_update=False, properties=None, wait=False)
async
¶
Create a new image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_data
|
bytes
|
Image data. |
required |
filename
|
str
|
Name of the image file. |
None
|
public
|
bool
|
Whether the image is public. |
False
|
auto_update
|
bool
|
Whether the image auto-updates. |
False
|
properties
|
Dict[str, str]
|
Image properties. |
None
|
wait
|
bool
|
Whether to wait for the operation to complete. |
False
|
Returns:
Type | Description |
---|---|
Union[Dict[str, Any], Image]
|
Union[Dict[str, Any], Image]: The operation response or the created image. |
Source code in incus_sdk/api/images.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
create_alias(name, target, description=None)
async
¶
Create an image alias.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the alias. |
required |
target
|
str
|
Target fingerprint. |
required |
description
|
str
|
Description of the alias. |
None
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The operation response. |
Source code in incus_sdk/api/images.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
delete(fingerprint, wait=False)
async
¶
Delete an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fingerprint
|
str
|
Fingerprint of the image. |
required |
wait
|
bool
|
Whether to wait for the operation to complete. |
False
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The operation response. |
Source code in incus_sdk/api/images.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
delete_alias(name)
async
¶
Delete an image alias.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the alias. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The operation response. |
Source code in incus_sdk/api/images.py
184 185 186 187 188 189 190 191 192 193 194 |
|
export(fingerprint, target_path)
async
¶
Export an image to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fingerprint
|
str
|
Fingerprint of the image. |
required |
target_path
|
str
|
Path to save the exported image. |
required |
Source code in incus_sdk/api/images.py
150 151 152 153 154 155 156 157 158 159 160 161 |
|
get(fingerprint)
async
¶
Get an image by fingerprint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fingerprint
|
str
|
Fingerprint of the image. |
required |
Returns:
Name | Type | Description |
---|---|---|
Image |
Image
|
The image. |
Source code in incus_sdk/api/images.py
44 45 46 47 48 49 50 51 52 53 54 55 |
|
get_alias(name)
async
¶
Get an image alias.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the alias. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The alias. |
Source code in incus_sdk/api/images.py
196 197 198 199 200 201 202 203 204 205 206 |
|
list(recursion=1)
async
¶
List all images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
recursion
|
int
|
Level of recursion for the response. |
1
|
Returns:
Type | Description |
---|---|
List[Image]
|
List[Image]: List of images. |
Source code in incus_sdk/api/images.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
update(fingerprint, properties, wait=False)
async
¶
Update an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fingerprint
|
str
|
Fingerprint of the image. |
required |
properties
|
Dict[str, Any]
|
New properties. |
required |
wait
|
bool
|
Whether to wait for the operation to complete. |
False
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The operation response. |
Source code in incus_sdk/api/images.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
update_alias(name, target=None, description=None)
async
¶
Update an image alias.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the alias. |
required |
target
|
str
|
New target fingerprint. |
None
|
description
|
str
|
New description. |
None
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The operation response. |
Source code in incus_sdk/api/images.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
Methods¶
list¶
async def list(recursion: int = 1) -> List[Image]
List all images.
Parameters:
- recursion
: Level of recursion for the response (default: 1).
Returns:
- A list of Image
objects.
get¶
async def get(fingerprint: str) -> Image
Get an image by fingerprint.
Parameters:
- fingerprint
: Fingerprint of the image.
Returns:
- An Image
object.
create¶
async def create(
image_data: bytes,
filename: str = None,
public: bool = False,
auto_update: bool = False,
properties: Dict[str, str] = None,
wait: bool = False,
) -> Union[Dict[str, Any], Image]
Create a new image.
Parameters:
- image_data
: Image data as bytes.
- filename
: Name of the image file (optional).
- public
: Whether the image is public (default: False).
- auto_update
: Whether the image auto-updates (default: False).
- properties
: Image properties as a dictionary (optional).
- wait
: Whether to wait for the operation to complete (default: False).
Returns:
- If wait
is True, returns the created Image
object.
- If wait
is False, returns the operation response as a dictionary.
Example:
# Create an image from a file
import aiofiles
async with aiofiles.open("image.tar.gz", "rb") as f:
image_data = await f.read()
image = await client.images.create(
image_data=image_data,
filename="image.tar.gz",
properties={
"description": "My custom image",
"os": "Ubuntu",
"release": "22.04"
},
public=True,
wait=True
)
delete¶
async def delete(
fingerprint: str,
wait: bool = False
) -> Dict[str, Any]
Delete an image.
Parameters:
- fingerprint
: Fingerprint of the image.
- wait
: Whether to wait for the operation to complete (default: False).
Returns: - The operation response as a dictionary.
update¶
async def update(
fingerprint: str,
properties: Dict[str, Any],
wait: bool = False
) -> Dict[str, Any]
Update an image.
Parameters:
- fingerprint
: Fingerprint of the image.
- properties
: New properties as a dictionary.
- wait
: Whether to wait for the operation to complete (default: False).
Returns: - The operation response as a dictionary.
export¶
async def export(
fingerprint: str,
target_path: str
) -> None
Export an image to a file.
Parameters:
- fingerprint
: Fingerprint of the image.
- target_path
: Path to save the exported image.
Returns: - None
create_alias¶
async def create_alias(
name: str,
target: str,
description: str = None
) -> Dict[str, Any]
Create an image alias.
Parameters:
- name
: Name of the alias.
- target
: Target fingerprint.
- description
: Description of the alias (optional).
Returns: - The operation response as a dictionary.
delete_alias¶
async def delete_alias(
name: str
) -> Dict[str, Any]
Delete an image alias.
Parameters:
- name
: Name of the alias.
Returns: - The operation response as a dictionary.
get_alias¶
async def get_alias(
name: str
) -> Dict[str, Any]
Get an image alias.
Parameters:
- name
: Name of the alias.
Returns: - The alias information as a dictionary.
update_alias¶
async def update_alias(
name: str,
target: str,
description: str = None
) -> Dict[str, Any]
Update an image alias.
Parameters:
- name
: Name of the alias.
- target
: New target fingerprint.
- description
: New description (optional).
Returns: - The operation response as a dictionary.