Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __new__(cls, name, bases, attrs):
if '__slots__' in attrs and name != 'Model': # pragma: no cover
raise TypeError('__slots__ should not be specified.')
attributes = {}
for_removal = []
managers = []
for key, val in attrs.items():
if type(val) == Attribute:
attributes[key] = val
for_removal.append(key)
if type(val) in (Manager, Parent):
managers.append(key)
for_removal.append(key)
for key in for_removal:
del attrs[key]
slots = list(attributes.keys())
if '__slots__' in attrs:
slots = slots + attrs['__slots__']
for base in bases:
if '__slots__' in dir(base):
slots = slots + base.__slots__
if len(managers) > 0:
slots = slots + managers
attrs['__slots__'] = slots
attrs['__attributes__'] = attributes
# 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
from pylxd import managers
class Cluster(model.Model):
"""An LXD Cluster.
"""
server_name = model.Attribute()
enabled = model.Attribute()
member_config = model.Attribute()
members = model.Manager()
def __init__(self, *args, **kwargs):
super(Cluster, self).__init__(*args, **kwargs)
self.members = managers.ClusterMemberManager(self.client, self)
@property
def api(self):
return self.client.api.cluster
@classmethod
def get(cls, client, *args):
"""Get cluster details"""
print(args)
response = client.api.cluster.get()
print(response.json())
container = cls(client, **response.json()['metadata'])
devices = model.Attribute()
ephemeral = model.Attribute()
expanded_config = model.Attribute()
expanded_devices = model.Attribute()
name = model.Attribute(readonly=True)
description = model.Attribute()
profiles = model.Attribute()
status = model.Attribute(readonly=True)
last_used_at = model.Attribute(readonly=True)
location = model.Attribute(readonly=True)
status_code = model.Attribute(readonly=True)
stateful = model.Attribute(readonly=True)
snapshots = model.Manager()
files = model.Manager()
@property
def api(self):
return self.client.api.containers[self.name]
class FilesManager(object):
"""A pseudo-manager for namespacing file operations."""
def __init__(self, client, container):
self._client = client
self._container = container
def put(self, filepath, data, mode=None, uid=None, gid=None):
"""Push a file to the container.
This pushes a single file to the containers file system named by
created_at = model.Attribute()
devices = model.Attribute()
ephemeral = model.Attribute()
expanded_config = model.Attribute()
expanded_devices = model.Attribute()
name = model.Attribute(readonly=True)
description = model.Attribute()
profiles = model.Attribute()
status = model.Attribute(readonly=True)
last_used_at = model.Attribute(readonly=True)
location = model.Attribute(readonly=True)
status_code = model.Attribute(readonly=True)
stateful = model.Attribute(readonly=True)
snapshots = model.Manager()
files = model.Manager()
@property
def api(self):
return self.client.api.containers[self.name]
class FilesManager(object):
"""A pseudo-manager for namespacing file operations."""
def __init__(self, client, container):
self._client = client
self._container = container
def put(self, filepath, data, mode=None, uid=None, gid=None):
"""Push a file to the container.