Revision 8a47b447 lib/rapi/client.py
b/lib/rapi/client.py | ||
---|---|---|
56 | 56 |
NODE_ROLE_OFFLINE = "offline" |
57 | 57 |
NODE_ROLE_REGULAR = "regular" |
58 | 58 |
|
59 |
# Internal constants |
|
60 |
_REQ_DATA_VERSION_FIELD = "__version__" |
|
61 |
_INST_CREATE_REQV1 = "instance-create-reqv1" |
|
62 |
|
|
59 | 63 |
|
60 | 64 |
class Error(Exception): |
61 | 65 |
"""Base error class for this module. |
... | ... | |
555 | 559 |
("/%s/instances/%s" % |
556 | 560 |
(GANETI_RAPI_VERSION, instance)), None, None) |
557 | 561 |
|
558 |
def CreateInstance(self, dry_run=False): |
|
562 |
def CreateInstance(self, mode, name, disk_template, disks, nics, |
|
563 |
**kwargs): |
|
559 | 564 |
"""Creates a new instance. |
560 | 565 |
|
566 |
More details for parameters can be found in the RAPI documentation. |
|
567 |
|
|
568 |
@type mode: string |
|
569 |
@param mode: Instance creation mode |
|
570 |
@type name: string |
|
571 |
@param name: Hostname of the instance to create |
|
572 |
@type disk_template: string |
|
573 |
@param disk_template: Disk template for instance (e.g. plain, diskless, |
|
574 |
file, or drbd) |
|
575 |
@type disks: list of dicts |
|
576 |
@param disks: List of disk definitions |
|
577 |
@type nics: list of dicts |
|
578 |
@param nics: List of NIC definitions |
|
561 | 579 |
@type dry_run: bool |
562 |
@param dry_run: whether to perform a dry run
|
|
580 |
@keyword dry_run: whether to perform a dry run
|
|
563 | 581 |
|
564 | 582 |
@rtype: int |
565 | 583 |
@return: job id |
566 | 584 |
|
567 | 585 |
""" |
568 |
# TODO: Pass arguments needed to actually create an instance. |
|
569 | 586 |
query = [] |
570 |
if dry_run: |
|
587 |
|
|
588 |
if kwargs.get("dry_run"): |
|
571 | 589 |
query.append(("dry-run", 1)) |
572 | 590 |
|
591 |
if _INST_CREATE_REQV1 in self.GetFeatures(): |
|
592 |
# All required fields for request data version 1 |
|
593 |
body = { |
|
594 |
_REQ_DATA_VERSION_FIELD: 1, |
|
595 |
"mode": mode, |
|
596 |
"name": name, |
|
597 |
"disk_template": disk_template, |
|
598 |
"disks": disks, |
|
599 |
"nics": nics, |
|
600 |
} |
|
601 |
|
|
602 |
conflicts = set(kwargs.iterkeys()) & set(body.iterkeys()) |
|
603 |
if conflicts: |
|
604 |
raise GanetiApiError("Required fields can not be specified as" |
|
605 |
" keywords: %s" % ", ".join(conflicts)) |
|
606 |
|
|
607 |
body.update((key, value) for key, value in kwargs.iteritems() |
|
608 |
if key != "dry_run") |
|
609 |
else: |
|
610 |
# TODO: Implement instance creation request data version 0 |
|
611 |
# When implementing version 0, care should be taken to refuse unknown |
|
612 |
# parameters and invalid values. The interface of this function must stay |
|
613 |
# exactly the same for version 0 and 1 (e.g. they aren't allowed to |
|
614 |
# require different data types). |
|
615 |
raise NotImplementedError("Support for instance creation request data" |
|
616 |
" version 0 is not yet implemented") |
|
617 |
|
|
573 | 618 |
return self._SendRequest(HTTP_POST, "/%s/instances" % GANETI_RAPI_VERSION, |
574 |
query, None)
|
|
619 |
query, body)
|
|
575 | 620 |
|
576 | 621 |
def DeleteInstance(self, instance, dry_run=False): |
577 | 622 |
"""Deletes an instance. |
Also available in: Unified diff