Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
snf-ganeti
Commits
2f7635f4
Commit
2f7635f4
authored
Oct 16, 2008
by
Oleksiy Mishchenko
Browse files
RAPI: Instance add/delete implementation.
Reviewed-by: iustinp
parent
29fc6636
Changes
2
Show whitespace changes
Inline
Side-by-side
lib/rapi/rlib1.py
View file @
2f7635f4
...
...
@@ -33,10 +33,9 @@ from ganeti import http
from
ganeti.rapi
import
baserlib
I_FIELDS
=
[
"name"
,
"os"
,
"pnode"
,
"snodes"
,
"admin_state"
,
"admin_ram"
,
"disk_template"
,
"ip"
,
"mac"
,
"bridge"
,
"sda_size"
,
"sdb_size"
,
"vcpus"
,
I_FIELDS
=
[
"name"
,
"os"
,
"pnode"
,
"snodes"
,
"admin_state"
,
"disk_template"
,
"ip"
,
"mac"
,
"bridge"
,
"sda_size"
,
"sdb_size"
,
"be/vcpus"
,
"be/memory"
,
"be/auto_balance"
,
"oper_state"
,
"status"
,
"tags"
]
N_FIELDS
=
[
"name"
,
"dtotal"
,
"dfree"
,
...
...
@@ -276,6 +275,17 @@ class R_instances_name(baserlib.R_Generic):
return
baserlib
.
MapFields
(
I_FIELDS
,
result
[
0
])
def
DELETE
(
self
):
"""Removes an instance.
"""
instance_name
=
self
.
items
[
0
]
op
=
ganeti
.
opcodes
.
OpRemoveInstance
(
instance_name
=
instance_name
,
ignore_failures
=
True
)
job_id
=
ganeti
.
cli
.
SendJob
([
op
])
return
job_id
class
R_instances_name_tags
(
baserlib
.
R_Generic
):
"""/instances/[instance_name]/tags resource.
...
...
lib/rapi/rlib2.py
View file @
2f7635f4
...
...
@@ -139,7 +139,6 @@ class R_2_instances(baserlib.R_Generic):
"""
DOC_URI
=
"/2/instances"
def
GET
(
self
):
"""Returns a list of all available instances.
...
...
@@ -197,6 +196,54 @@ class R_2_instances(baserlib.R_Generic):
return
baserlib
.
BuildUriList
(
instanceslist
,
"/2/instances/%s"
,
uri_fields
=
(
"id"
,
"uri"
))
def
PUT
(
self
):
"""Create an instance.
Returns:
A job id.
"""
opts
=
self
.
post_data
# beparams
mem
=
opts
.
get
(
'mem'
,
None
)
vcpus
=
opts
.
get
(
'vcpus'
,
None
)
auto_balance
=
opts
.
get
(
'auto_balance'
,
None
)
beparams
=
{}
for
key
,
const
in
[(
mem
,
constants
.
BE_MEMORY
),
(
vcpus
,
constants
.
BE_VCPUS
),
(
auto_balance
,
constants
.
BE_AUTO_BALANCE
)]:
if
key
is
not
None
:
beparams
[
const
]
=
key
op
=
ganeti
.
opcodes
.
OpCreateInstance
(
instance_name
=
opts
.
get
(
'name'
),
disk_size
=
opts
.
get
(
'size'
,
20
*
1024
),
swap_size
=
opts
.
get
(
'swap'
,
4
*
1024
),
disk_template
=
opts
.
get
(
'disk_template'
,
None
),
mode
=
constants
.
INSTANCE_CREATE
,
os_type
=
opts
.
get
(
'os'
),
pnode
=
opts
.
get
(
'pnode'
),
snode
=
opts
.
get
(
'snode'
),
ip
=
opts
.
get
(
'ip'
,
'none'
),
bridge
=
opts
.
get
(
'bridge'
,
None
),
start
=
opts
.
get
(
'start'
,
True
),
ip_check
=
opts
.
get
(
'ip_check'
,
True
),
wait_for_sync
=
opts
.
get
(
'wait_for_sync'
,
True
),
mac
=
opts
.
get
(
'mac'
,
'auto'
),
hypervisor
=
opts
.
get
(
'hypervisor'
,
None
),
hvparams
=
opts
.
get
(
'hvparams'
,
{}),
beparams
=
beparams
,
iallocator
=
opts
.
get
(
'iallocator'
,
None
),
file_storage_dir
=
opts
.
get
(
'file_storage_dir'
,
None
),
file_driver
=
opts
.
get
(
'file_driver'
,
'loop'
),
)
job_id
=
ganeti
.
cli
.
SendJob
([
op
])
return
job_id
class
R_2_instances_name_tags
(
baserlib
.
R_Generic
):
"""/2/instances/[instance_name]/tags resource.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment