def ensure_user_exists( client, user_email, private_key, **user_kw ): """ Given a user email, ensure that the corresponding Syndicate user exists with the given fields. This method is idempotent. This method can only be called by an admin user. @private_key must be a PEM-encoded 4096-bit RSA private key Return the (created, updated, user), where created==True if the user was created and created==False if the user was read. Raise an exception on error. """ created = False updated = False private_key = private_key.strip() try: private_key = CryptoKey.importKey( private_key ).exportKey() public_key = CryptoKey.importKey( private_key ).publickey().exportKey() except: log.error("Could not import private key") raise Exception("Could not import private key") try: user = rpc.ms_rpc( client, "read_user", user_email ) except Exception, e: # transport error log.exception(e) raise Exception("Failed to read '%s'" % user_email )
def ensure_user_exists(client, user_email, private_key, **user_kw): """ Given a user email, ensure that the corresponding Syndicate user exists with the given fields. This method is idempotent. This method can only be called by an admin user. @private_key must be a PEM-encoded 4096-bit RSA private key Return the (created, updated, user), where created==True if the user was created and created==False if the user was read. Raise an exception on error. """ created = False updated = False private_key = private_key.strip() try: private_key = CryptoKey.importKey(private_key).exportKey() public_key = CryptoKey.importKey(private_key).publickey().exportKey() except: log.error("Could not import private key") raise Exception("Could not import private key") try: user = rpc.ms_rpc(client, "read_user", user_email) except Exception, e: # transport error log.exception(e) raise Exception("Failed to read '%s'" % user_email)
def ensure_gateway_absent( client, gateway_name ): """ Ensure that a particular gateway does not exist. Return True on success return False if we can't connect raise exception on error. """ rc = rpc.ms_rpc( client, "delete_gateway", gateway_name ) return rc
def ensure_user_absent( client, user_email ): """ Ensure that a given OpenCloud user's associated Syndicate user record has been deleted. This method is idempotent. Returns True on success Raises an exception on error """ return rpc.ms_rpc( client, "delete_user", user_email )
def ensure_volume_absent( client, volume_name ): """ Ensure that a volume no longer exists. This method is idempotent. Only the volume owner can call it. Return True on success Raise exception on error """ rc = rpc.ms_rpc( client, "delete_volume", volume_name ) return rc
def ensure_gateway_absent( client, gateway_name ): """ Ensure that a particular gateway does not exist. Return True on success return False if we can't connect raise exception on error. """ try: rc = rpc.ms_rpc( client, "delete_gateway", gateway_name ) return rc except MissingCertException, MissingKeyException: log.debug("Missing cert or key; assuming deleted") return True
def ensure_gateway_absent(client, gateway_name): """ Ensure that a particular gateway does not exist. Return True on success return False if we can't connect raise exception on error. """ try: rc = rpc.ms_rpc(client, "delete_gateway", gateway_name) return rc except MissingCertException, MissingKeyException: log.debug("Missing cert or key; assuming deleted") return True
def ensure_volume_absent( client, volume_name ): """ Ensure that a volume no longer exists. This method is idempotent. Only the volume owner can call it. Return True on success Raise exception on error """ try: rc = rpc.ms_rpc( client, "delete_volume", volume_name ) return rc except MissingCertException, MissingKeyException: log.debug("Missing cert or private key; assuming deleted") return True
def ensure_user_absent( client, user_email ): """ Ensure that a given OpenCloud user's associated Syndicate user record has been deleted. This method is idempotent. Returns True on success Raises an exception on error """ try: rc = rpc.ms_rpc( client, "delete_user", user_email ) return rc except MissingCertException, MissingKeyException: log.debug("Missing cert or private key; assuming deleted") return True
def ensure_volume_absent(client, volume_name): """ Ensure that a volume no longer exists. This method is idempotent. Only the volume owner can call it. Return True on success Raise exception on error """ try: rc = rpc.ms_rpc(client, "delete_volume", volume_name) return rc except MissingCertException, MissingKeyException: log.debug("Missing cert or private key; assuming deleted") return True
def ensure_user_absent(client, user_email): """ Ensure that a given OpenCloud user's associated Syndicate user record has been deleted. This method is idempotent. Returns True on success Raises an exception on error """ try: rc = rpc.ms_rpc(client, "delete_user", user_email) return rc except MissingCertException, MissingKeyException: log.debug("Missing cert or private key; assuming deleted") return True
def ensure_volume_exists( client, volume_name, description, blocksize, user_email, **attrs ): """ Ensure that a volume exists and is consistent with the given attributes. This method is idempotent. Returns (created, updated, volume) on success, where created/updated are booleans Raises an exception on error * i.e. if the user doesn't exist or is over-quota """ created = False updated = False try: volume = rpc.ms_rpc( client, "read_volume", volume_name ) except Exception, e: # transport error log.exception(e) raise Exception("Failed to read '%s'" % volume_name)
def ensure_volume_exists(client, volume_name, description, blocksize, user_email, **attrs): """ Ensure that a volume exists and is consistent with the given attributes. This method is idempotent. Returns (created, updated, volume) on success, where created/updated are booleans Raises an exception on error * i.e. if the user doesn't exist or is over-quota """ created = False updated = False try: volume = rpc.ms_rpc(client, "read_volume", volume_name) except Exception, e: # transport error log.exception(e) raise Exception("Failed to read '%s'" % volume_name)
else: # update it try: rc = client.update_gateway( gateway_name, **inconsistent ) except Exception, e: log.exception(e) raise Exception("Failed to update '%s'" % gateway_name) gateway.update( inconsistent ) updated = True if gateway is None: # create the gateway try: gateway = rpc.ms_rpc( client, "create_gateway", volume=volume_name, email=user_email, type=gateway_type, name=gateway_name, host=host, port=port, **gateway_kw ) created = True except Exception, e: # transport, collision, or missing Volume or user log.exception(e) raise e return (created, updated, gateway) #------------------------------- def ensure_gateway_absent( client, gateway_name ): """ Ensure that a particular gateway does not exist. Return True on success return False if we can't connect
port=port, **gateway_kw) if len(inconsistent.keys()) > 0: log.debug("Inconsistent: %s" % ",".join(inconsistent.keys())) # update the gateway to be consistent, if possible if 'volume_id' in inconsistent.keys( ) or 'owner_id' in inconsistent.keys(): # can't do much about this raise Exception("Cannot make gateway '%s' consistent" % gateway_name) else: # update it try: rc = rpc.ms_rpc(client, "update_gateway", gateway_name, **inconsistent) except Exception, e: log.exception(e) raise Exception("Failed to update '%s'" % gateway_name) gateway.update(inconsistent) updated = True if gateway is None: # create the gateway try: gateway = rpc.ms_rpc(client, "create_gateway", volume=volume_name, email=user_email,