Basic connection object that makes all API requests.
The smartdc.datacenter.DataCenter is the basic connection unit with the CloudAPI, and it maintains the data it requires for further requests. It lazily updates some internal data as and when the user requests it, and only accesses the REST API on method calls (never on attribute access).
A smartdc.datacenter.DataCenter object may be instantiated without any parameters, but practically speaking, the key_id and secret parameters are necessary before any meaningful requests may be made.
Parameters: |
|
---|
The location is notionally a hostname, but it may be expressed as an FQDN, one of the keys to the known_locations dict, or, as a fallback, a bare hostname as prefix to the API_HOST_SUFFIX. The default location is ‘us-west-1’, because that is where ‘api.joyentcloud.com’ redirects to at the time of writing.
The known_locations dict allows for custom access to a private cloud.
Attributes:
Variables: |
|
---|
POST /:login/keys
Parameters: |
|
---|
Uploads a public key to be added to the account’s credentials.
GET /
Returns : | a programmatically-generated API summary using HTTP verbs and URL templates |
---|---|
Return type: | dict |
Parameters: |
|
---|
If no key_id or secret were entered on initialization, or there is a need to change the existing authentication credentials, one may authenticate with a key_id and secret.
Protocol + hostname
POST /:login/machines
Provision a machine in the current smartdc.datacenter.DataCenter, returning an instantiated smartdc.machine.Machine object. All of the parameter values are optional, as they are assigned default values by the datacenter’s API itself.
Parameters: |
|
---|---|
Return type: |
If package, image, or dataset are passed a dict containing a name key (in the case of package) or an id key (in the case of image or dataset), it passes the corresponding value. The server API appears to resolve incomplete or ambiguous dataset URNs with the highest version number.
Parameters: | name (basestring) – location key |
---|---|
Returns : | a new DataCenter object |
This method treats the ‘name’ argument as a location key (on the known_locations attribute dict) or FQDN, and keeps existing authentication and other configuration from this object.
GET /:login/datacenters
Returns : | all datacenters (mapping from short location key to full URL) that this cloud is aware of |
---|---|
Return type: | dict |
This method also updates the local known_locations attribute based upon this information.
GET /:login/datasets/:id
Parameters: | identifier (basestring or dict) – unique ID or URN for a dataset |
---|---|
Return type: | dict |
Gets a single dataset identified by the unique ID or URN. URNs are also prefix-matched. If passed a dict that contains an urn or id key, it uses the respective value as the identifier.
GET /:login/datasets
Parameters: |
|
---|---|
Returns : | datasets (operating system templates) available in this datacenter |
Return type: | list of dicts |
GET /:login/packages
Returns : | the default package for this datacenter |
---|---|
Return type: | dict or None |
Requests all the packages in this datacenter, filters for the default, and returns the corresponding dict, if a default has been defined.
DELETE /:login/keys/:key
Parameters: | key_id (basestring) – identifier for an individual key record for the account |
---|
Deletes an SSH key from the server identified by key_id.
GET /:login/images/:id
Parameters: | identifier (basestring or dict) – match on the listed image identifier |
---|---|
Returns : | the details of the given image matching the identifier |
Return type: | dict |
A string or a dictionary containing an id key may be passed in.
GET /:login/images
Parameters: |
|
---|---|
Returns : | available machine images in this datacenter |
Return type: | list of dicts |
GET /:login/keys/:key
Parameters: | key_id (basestring) – identifier for an individual key record for the account |
---|---|
Returns: | details of the key |
Return type: | dict |
GET /:login/keys
Returns : | all public keys on record for the authenticated account. |
---|---|
Return type: | list of dicts |
GET /:login/machines/:id
Parameters: | machine_id (basestring) – unique identifier for a machine to be found in the datacenter |
---|---|
Return type: | smartdc.machine.Machine |
GET /:login/machines
Query for machines in the current DataCenter matching the input criteria, returning a list of instantiated smartdc.machine.Machine objects.
Parameters: |
|
---|---|
Return type: | list of smartdc.machine.Machines |
The limit and offset are the REST API’s raw paging mechanism. Alternatively, one can let paged remain False, and let the method call attempt to collect all of the machines in multiple calls.
GET /:login
Returns : | basic information about the authenticated account |
---|---|
Return type: | dict |
GET /:login/networks/:id
Parameters: | identifier (basestring or dict) – match on the listed network identifier |
---|---|
Returns : | characteristics of the requested network |
Return type: | dict |
Either a string or a dictionary with an id key may be passed in.
GET /:login/networks
Parameters: |
|
---|---|
Returns : | network available in this datacenter |
Return type: | list of dicts |
HEAD /:login/machines
Counts the number of machines total, or that match the predicates as with machines().
Parameters: |
|
---|---|
Returns : | a count of the number of machines (matching the predicates) owned by the user at this datacenter |
Return type: | int |
GET /:login/packages/:package
Parameters: | name – the name identifying the package |
---|---|
Return type: | dict |
Gets a dict representing resource values for a package by name. If passed a dict containing a name key, it uses the corresponding value.
GET /:login/packages
Parameters: |
|
---|---|
Returns : | packages (machine “sizes”, with resource types and values) available in this datacenter. |
Return type: | list of dicts |
GET /:login/machines/:machine
Parameters: |
|
---|---|
Return type: | dict |
Primarily used internally to get a raw dict for a single machine.
(Primarily) internal method for making all requests to the datacenter.
Parameters: |
|
---|---|
Returns : | tuple of decoded response body & Response object |
Raises : | client (4xx) errors |
Base URL for SmartDC requests