NVZ is right. The likening of the guard to an obedient and friendly dog is first introduced by the simile in the line that reads as follows:
When he saw who I was the guard began behaving like a spaniel.
Note that a simile is a comparison of two unlike things using the words "like" or "as". Here, the guard is portrayed as a dog.
As NVZ notes, once this foundation is laid, the simile transitions to a metaphor, in which the speaker directly continues to refer to the guard as a spaniel. A comparison of two unlike things in a more direct and literal manner is a metaphor:
He lay on his back inviting me to tickle his tummy...The spaniel then walked away, having let me pass.
Obviously, the guard didn't literally lie on his back and let the speaker scratch his tummy. Rather, the speaker wishes to suggest that the guard, rather than preventing him from entering whatever location he is watching over, was approachable and behaved amiably, almost like a dog that seeks human interaction and voluntarily presents its tummy for some human lovin'. More likely, the guard got to chatting with the visitor in a friendly manner, cracked a couple hearty jokes, gave him a smile, and let him pass.
All of this serves to make the passage more lively and humorous.