Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
response = client.api.cluster.get()
print(response.json())
container = cls(client, **response.json()['metadata'])
return container
class ClusterMember(model.Model):
"""A LXD cluster member."""
url = model.Attribute(readonly=True)
database = model.Attribute(readonly=True)
server_name = model.Attribute(readonly=True)
status = model.Attribute(readonly=True)
message = model.Attribute(readonly=True)
cluster = model.Parent()
@classmethod
def get(cls, client, server_name):
"""Get a cluster member by name."""
response = client.api.cluster.members[server_name].get()
return cls(client, **response.json()['metadata'])
@classmethod
def all(cls, client, *args):
"""Get all cluster members."""
response = client.api.cluster.members.get()
nodes = []
for node in response.json()['metadata']:
server_name = node.split('/')[-1]
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
from pylxd.exceptions import LXDAPIExtensionNotAvailable
from pylxd.models import _model as model
class Network(model.Model):
"""Model representing a LXD network."""
name = model.Attribute()
description = model.Attribute()
type = model.Attribute()
config = model.Attribute()
managed = model.Attribute(readonly=True)
used_by = model.Attribute(readonly=True)
@classmethod
def exists(cls, client, name):
"""
Determine whether network with provided name exists.
:param client: client instance
:type client: :class:`~pylxd.client.Client`
:param name: name of the network
:type name: str
:returns: `True` if network exists, `False` otherwise
:rtype: bool
"""
def get(cls, client, *args):
"""Get cluster details"""
print(args)
response = client.api.cluster.get()
print(response.json())
container = cls(client, **response.json()['metadata'])
return container
class ClusterMember(model.Model):
"""A LXD cluster member."""
url = model.Attribute(readonly=True)
database = model.Attribute(readonly=True)
server_name = model.Attribute(readonly=True)
status = model.Attribute(readonly=True)
message = model.Attribute(readonly=True)
cluster = model.Parent()
@classmethod
def get(cls, client, server_name):
"""Get a cluster member by name."""
response = client.api.cluster.members[server_name].get()
return cls(client, **response.json()['metadata'])
@classmethod
def all(cls, client, *args):
"""Get all cluster members."""
response = client.api.cluster.members.get()
(self._smart_encode(line) for line in self.payload),
binary=True
)
else:
self.send(self._smart_encode(self.payload), binary=True)
self.send(b"", binary=False)
class Snapshot(model.Model):
"""A container snapshot."""
name = model.Attribute()
created_at = model.Attribute()
stateful = model.Attribute()
container = model.Parent()
@property
def api(self):
return self.client.api.containers[
self.container.name].snapshots[self.name]
@classmethod
def get(cls, client, container, name):
response = client.api.containers[
container.name].snapshots[name].get()
snapshot = cls(
client, container=container,
**response.json()['metadata'])
# Snapshot names are namespaced in LXD, as
# container-name/snapshot-name. We hide that implementation
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from pylxd.models import _model as model
class Profile(model.Model):
"""A LXD profile."""
config = model.Attribute()
description = model.Attribute()
devices = model.Attribute()
name = model.Attribute(readonly=True)
used_by = model.Attribute(readonly=True)
@classmethod
def exists(cls, client, name):
"""Determine whether a profile exists."""
try:
client.profiles.get(name)
return True
except cls.NotFound:
return False
@classmethod
def get(cls, client, name):
"""Get a profile."""
# License for the specific language governing permissions and limitations
# under the License.
import binascii
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.serialization import Encoding
from pylxd.models import _model as model
class Certificate(model.Model):
"""A LXD certificate."""
certificate = model.Attribute()
fingerprint = model.Attribute()
type = model.Attribute()
name = model.Attribute()
@classmethod
def get(cls, client, fingerprint):
"""Get a certificate by fingerprint."""
response = client.api.certificates[fingerprint].get()
return cls(client, **response.json()['metadata'])
@classmethod
def all(cls, client):
"""Get all certificates."""
response = client.api.certificates.get()