<s> __author__ = '<STR_LIT>' <EOL> from tests . config import * <EOL> from nsxramlclient . client import NsxClient <EOL> import time <EOL> def get_all_sec_groups ( session ) : <EOL> result = session . read ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> session . view_response ( result ) <EOL> def get_vm_in_sec_group ( session , secgroupid ) : <EOL> response = session . read ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : secgroupid } ) <EOL> session . view_response ( response ) <EOL> def get_ips_in_sec_group ( session , secgroupid ) : <EOL> response = session . read ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : secgroupid } ) <EOL> session . view_response ( response ) <EOL> def get_macs_in_sec_group ( session , secgroupid ) : <EOL> response = session . read ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : secgroupid } ) <EOL> session . view_response ( response ) <EOL> def get_vnics_in_sec_group ( session , secgroupid ) : <EOL> response = session . read ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : secgroupid } ) <EOL> session . view_response ( response ) <EOL> def sec_group_add_member ( session , secgroupid , member_moref ) : <EOL> add_response = session . update ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : secgroupid , <EOL> '<STR_LIT>' : member_moref } ) <EOL> session . view_response ( add_response ) <EOL> def sec_group_delete_member ( session , secgroupid , member_moref ) : <EOL> add_response = session . delete ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : secgroupid , <EOL> '<STR_LIT>' : member_moref } ) <EOL> session . view_response ( add_response ) <EOL> def get_sec_group_valid_types ( session ) : <EOL> response = session . read ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> session . view_response ( response ) <EOL> return response [ '<STR_LIT:body>' ] <EOL> def get_sec_group_by_vm ( session , vmid ) : <EOL> response = session . read ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : vmid } ) <EOL> session . view_response ( response ) <EOL> def get_sec_group_by_id ( session , secgroupid ) : <EOL> response = session . read ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : secgroupid } ) <EOL> session . view_response ( response ) <EOL> return response [ '<STR_LIT:body>' ] <EOL> def update_sec_group ( session , secgroupid , body ) : <EOL> response = session . update ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : secgroupid } , request_body_dict = body ) <EOL> session . view_response ( response ) <EOL> def delete_sec_group ( session , secgroupid ) : <EOL> response = session . delete ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : secgroupid } , <EOL> query_parameters_dict = { '<STR_LIT>' : '<STR_LIT:true>' } ) <EOL> session . view_response ( response ) <EOL> def add_dynamic_match ( session , secgroupid , criteria = '<STR_LIT>' , key = '<STR_LIT>' ) : <EOL> body_content = session . read ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : secgroupid } ) [ '<STR_LIT:body>' ] <EOL> extracted_schema = session . extract_resource_body_schema ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> dynamic_member_def = extracted_schema [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> dynamic_member_def [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> dynamic_member_def [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT:true>' <EOL> dynamic_member_def [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:key>' ] = '<STR_LIT>' <EOL> dynamic_member_def [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:value>' ] = '<STR_LIT>' <EOL> body_content [ '<STR_LIT>' ] . update ( { '<STR_LIT>' : dynamic_member_def } ) <EOL> update_sec_group ( session , secgroupid , body_content ) <EOL> def empty_sec_group_create ( session , name ) : <EOL> new_sec_group = session . extract_resource_body_schema ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> new_sec_group [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] = name <EOL> new_sec_group [ '<STR_LIT>' ] . pop ( '<STR_LIT>' ) <EOL> new_sec_group [ '<STR_LIT>' ] . pop ( '<STR_LIT>' ) <EOL> new_sec_group [ '<STR_LIT>' ] . pop ( '<STR_LIT>' ) <EOL> new_sec_group [ '<STR_LIT>' ] . pop ( '<STR_LIT:type>' ) <EOL> new_sec_group [ '<STR_LIT>' ] . pop ( '<STR_LIT>' ) <EOL> session . view_body_dict ( new_sec_group ) <EOL> create_response = session . create ( '<STR_LIT>' , uri_parameters = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> request_body_dict = new_sec_group ) <EOL> session . view_response ( create_response ) <EOL> return create_response [ '<STR_LIT:body>' ] <EOL> def main ( ) : <EOL> s = NsxClient ( nsxraml_file , nsxmanager , nsx_username , nsx_password , debug = True ) <EOL> get_sec_group_valid_types ( s ) <EOL> new_sec_group = empty_sec_group_create ( s , '<STR_LIT>' ) <EOL> print new_sec_group <EOL> sec_group_add_member ( s , new_sec_group , '<STR_LIT>' ) <EOL> get_all_sec_groups ( s ) <EOL> add_dynamic_match ( s , new_sec_group ) <EOL> get_sec_group_by_id ( s , new_sec_group ) <EOL> get_sec_group_by_vm ( s , '<STR_LIT>' ) <EOL> get_vm_in_sec_group ( s , new_sec_group ) <EOL> get_ips_in_sec_group ( s , new_sec_group ) <EOL> get_macs_in_sec_group ( s , new_sec_group ) <EOL> get_vnics_in_sec_group ( s , new_sec_group ) <EOL> time . sleep ( <NUM_LIT:20> ) <EOL> sec_group_delete_member ( s , new_sec_group , '<STR_LIT>' ) <EOL> time . sleep ( <NUM_LIT:20> ) <EOL> delete_sec_group ( s , new_sec_group ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
