def client(self, func, *args, **kwargs): try: if CONF.host == kwargs['host']: lxd_client = api.API() else: lxd_client = api.API(host=kwargs['host']) except lxd_exceptions.APIError as ex: msg = (_('Unable to connect to %(host)s %(reason)s') % { 'host': kwargs['host'], 'reason': ex }) raise exception.NovaException(msg) func = getattr(self, "container_%s" % func) return func(lxd_client, **kwargs)
def upload_image(image): alias = '{}/{}/{}/{}'.format(image['os'], image['release'], image['arch'], image['variant']) lxd = api.API() imgs = api.API(host='images.linuxcontainers.org') d = imgs.alias_show(alias) meta = d[1]['metadata'] tgt = meta['target'] try: lxd.alias_update(meta) except lxd_exceptions.APIError as ex: if ex.status_code == 404: lxd.alias_create(meta) return tgt
def __init__(self): self.lxd = api.API()
# 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. import uuid from pylxd import api # Let's pick a random name, avoiding clashes CONTAINER_NAME = str(uuid.uuid1()) lxd = api.API() try: lxd.container_defined(CONTAINER_NAME) except Exception as e: print("Container doesnt exist: %s" % e) config = {'name': CONTAINER_NAME, 'source': {'type': 'none'}} lxd.container_init(config) if lxd.container_defined(CONTAINER_NAME): print("Container is running") else: print("Whoops!") containers = lxd.container_list() for x in containers: lxd.container_destroy(x)
def setUp(self): super(LXDAPITestBase, self).setUp() self.lxd = api.API()
def __init__(self): self.connection = api.API() self.container_dir = container_dir.LXDContainerDirectories() self.lock_path = str(os.path.join(CONF.instances_path, 'locks'))
def delete_image(image): lxd = api.API() lxd.image_delete(image)