/usr/lib/python2.7/dist-packages/provisioningserver/custom_hardware/utils.py is in python-maas-provisioningserver 1.5.4+bzr2294-0ubuntu1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 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 | # Copyright 2013 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
from __future__ import (
absolute_import,
print_function,
unicode_literals,
)
str = None
__metaclass__ = type
from logging import getLogger
from apiclient.maas_client import (
MAASClient,
MAASDispatcher,
MAASOAuth,
)
from provisioningserver.auth import get_recorded_api_credentials
from provisioningserver.cluster_config import get_maas_url
import simplejson as json
logger = getLogger(__name__)
def create_node(mac, arch, power_type, power_parameters):
api_credentials = get_recorded_api_credentials()
if api_credentials is None:
raise Exception('Not creating node: no API key yet.')
client = MAASClient(
MAASOAuth(*api_credentials), MAASDispatcher(),
get_maas_url())
data = {
'architecture': arch,
'power_type': power_type,
'power_parameters': json.dumps(power_parameters),
'mac_addresses': mac,
'autodetect_nodegroup': 'true'
}
return client.post('/api/1.0/nodes/', 'new', **data)
def escape_string(data):
return repr(data).decode("ascii")
|