Creating Users and Passwords

This set of features is a part of the FlexSwitch Appliance.

Creating a User

To create a user, use the CLI, REST (cURL), or Python to create a user object. Examples of each method are shown below.

Json Data Model

}
curl -X POST -H ‘Content-Type: application/json’ –header ‘Accept: application/json’ -d ‘{<Model Object as json-Data>}’ http://device-management-IP:8080/public/v1/config/User
    "NAME": "SwitchUser",
    "Access": "Bash",
    "DefaultShell": "Bash"
}

REST (cURL) Requests

CREATE (POST)

curl -X POST -H ‘Content-Type: application/json’ –header ‘Accept: application/json’ -d ‘{<Model Object as json-Data>}’ http://device-management-IP:8080/public/v1/config/User

Python Calls

CREATE

from flexswitchV2 import FlexSwitch

if __name__ == '__main__':
    switchIP := "192.168.56.101"
    swtch = FlexSwitch (switchIP, 8080)  # Instantiate object to talk to flexSwitch
    response, error = swtch.createUser(Name=name, Access=access, DefaultShell=shell)

    if error != None: #Error not being None implies there is some problem
        print error
    else :
    print 'Success'

CLI Example

In the following example a user is created with access to the CLI only.

c88f38a4988e(config)#user snapuser
c88f38a4988e(config-user)#Access CLI
c88f38a4988e(config-user)#DefaultShell CLI
c88f38a4988e(config-user)#apply

Applying Config:
id: 2   object: User   status: APPLIED CONFIG  valid: True delete: False num user cmds: 5
 command               attr            value        model attr      iskey    required    userprov    time provisioned
------------------------------------------------------------------------------------------------------------------------------
 user snapuser         user            snapuser     Name            True     X           X           Mon Jun  5 18:16:04 2017
 Access CLIOnly        Access          CLI      Access          False                X           Mon Jun  5 18:16:09 2017
 DefaultShell CLI      DefaultShell    CLI          DefaultShell    False                X           Mon Jun  5 18:16:12 2017

sdk:createUser(snapuser,Access=CLI,Password=snaproute,Group=admin,DefaultShell=CLI) result: SUCCESS: http status code: 201
-------------------------------------------------------------------------------------------------------------------------------

Editing a User

Warning

You cannot update a user name. In order to change a user name, you must first delete the user.

To edit (update) a user, use the CLI, REST (cURL), or Python to update a user. Attributes that can be changed are:

  • Access
  • DefaultShell

REST (cURL) Requests

UPDATE(PATCH) By Key

curl -X PATCH -H ‘Content-Type: application/json’ -d ‘{<Model Object as json data>}’ http://device-management-IP:8080/public/v1/config/User

UPDATE(PATCH) By ID

curl -X PATCH -H ‘Content-Type: application/json’ -d ‘{<Model Object as json data>}’ http://device-management-IP:8080/public/v1/config/User<uuid>

DELETE By Key

curl -X DELETE -i -H ‘Accept:application/json’ -d ‘{<Model Object as json data>}’ http://device-management-IP:8080/public/v1/config/User

DELETE By ID

curl -X DELETE http://device-management-IP:8080/public/v1/config/User<uuid>

Python Calls

GET By Key

from flexswitchV2 import FlexSwitch

if __name__ == '__main__':
    switchIP := "192.168.56.101"
    swtch = FlexSwitch (switchIP, 8080)  # Instantiate object to talk to flexSwitch
    response, error = swtch.getUser(User=user)

    if error != None: #Error not being None implies there is some problem
        print error
    else :
        print 'Success'

GET BY ID

from flexswitchV2 import FlexSwitch

if __name__ == '__main__':
    switchIP := "192.168.56.101"
    swtch = FlexSwitch (switchIP, 8080)  # Instantiate object to talk to flexSwitch
    response, error = swtch.getUserById(ObjectId=objectid)

    if error != None: #Error not being None implies there is some problem
        print error
    else :
    print 'Success'

GET ALL

from flexswitchV2 import FlexSwitch

if __name__ == '__main__':
    switchIP := "192.168.56.101"
    swtch = FlexSwitch (switchIP, 8080)  # Instantiate object to talk to flexSwitch
    response, error = swtch.getAllUsers()

    if error != None: #Error not being None implies there is some problem
        print error
    else :
        print 'Success'

CREATE

from flexswitchV2 import FlexSwitch

if __name__ == '__main__':
    switchIP := "192.168.56.101"
    swtch = FlexSwitch (switchIP, 8080)  # Instantiate object to talk to flexSwitch
    response, error = swtch.createUser(Name=name, Access=access, DefaultShell=shell)

    if error != None: #Error not being None implies there is some problem
        print error
    else :
    print 'Success'

UPDATE

from flexswitchV2 import FlexSwitch

if __name__ == '__main__':
    switchIP := "192.168.56.101"
    swtch = FlexSwitch (switchIP, 8080)  # Instantiate object to talk to flexSwitch
    response, error = swtch.updateUser(User=user, [Attribute_1=attribute-1],..[Attribute_n=attribute_n])

    if error != None: #Error not being None implies there is some problem
        print error
    else :
        print 'Success'

UPDATE BY ID

from flexswitchV2 import FlexSwitch

if __name__ == '__main__':
    switchIP := "192.168.56.101"
    swtch = FlexSwitch (switchIP, 8080)  # Instantiate object to talk to flexSwitch
    response, error = swtch.updateUserById(ObjectId=objectId, [Attribute_1=attribute_1],..[Attribute_n=attribute_n])

    if error != None: #Error not being None implies there is some problem
        print error
    else :
        print 'Success'

DELETE

from flexswitchV2 import FlexSwitch

if __name__ == '__main__':
    switchIP := "192.168.56.101"
    swtch = FlexSwitch (switchIP, 8080)  # Instantiate object to talk to flexSwitch
    response, error = swtch.deleteUser(Name=name)

    if error != None: #Error not being None implies there is some problem
        print error
    else :
    print 'Success'

DELETE By ID

from flexswitchV2 import FlexSwitch

if __name__ == '__main__':
    switchIP := "192.168.56.101"
    swtch = FlexSwitch (switchIP, 8080)  # Instantiate object to talk to flexSwitch
    response, error = swtch.deleteUserById(ObjectId=objectid)

    if error != None: #Error not being None implies there is some problem
        print error
    else :
        print 'Success'

Creating a Password

To create a password, use the CLI, REST (cURL), or Python to create a password object. Examples of each method are shown below.

Note

Passwords are not stored in FlexSwitch, they are managed by the underlying Linux OS.

JSON Data Model

{
    "Name" :"username",
    "Password":"mys3cr3t$s@uc3!"
}

REST (cURL) Requests

action/UserPassword url -H "Content-Type: application/json" -d ‘{}’ -X POST http://device-management-IP:8080/public/v1/action/UserPassword

Python Calls

Changing a Password

To create a password, use the CLI, REST (cURL), or Python to create a password object. Examples of each method are shown below.

REST (cURL) Requests

Note

Unlike most of the REST request, changing the password envokes the execute endpoint.

EXECUTE

curl -H "Content-Type: application/json" -d '{"Name":"user1", "Password":"snaproute1"}' -X POST http://192.168.100.199:8080/public/v1/action/UserPassword

Python Calls

EXECUTE

from flexswitchV2 import FlexSwitch

if __name__ == '__main__':
    switchIP := "192.168.56.101"
    swtch = FlexSwitch (switchIP, 8080)  # Instantiate object to talk to flexSwitch
    response, error = swtch.executeUserPassword(Name=name, Password=newpassword)

    if error != None: #Error not being None implies there is some problem
        print error
    else :
    print 'Success'

CLI Example

Assigning or changing a user password in the CLI is done through the user <UserName> password <newPassword> command.

localhost#user snaprouteUserName password som3newpa$$w0rd 
localhost#apply