예제 #1
0
def org(ctx, org_name):
    """
    Set vManage org
    """

    vmanage_settings = Settings(ctx.auth, ctx.host, ctx.port)
    vmanage_settings.set_vmanage_org(org_name)
예제 #2
0
def ca_type(ctx, type_):
    """
    Set vManage CA type
    """

    vmanage_settings = Settings(ctx.auth, ctx.host)
    vmanage_settings.set_vmanage_ca_type(type_)
예제 #3
0
def vbond(ctx, ip, port):
    """
    Set vBond
    """

    vmanage_settings = Settings(ctx.auth, ctx.host)
    vmanage_settings.set_vmanage_vbond(ip, port)
예제 #4
0
def ca_type(ctx):
    """
    Get vManage CA type
    """

    vmanage_settings = Settings(ctx.auth, ctx.host)
    result = vmanage_settings.get_vmanage_ca_type()
    click.echo(result)
예제 #5
0
def vbond(ctx):
    """
    Get IP address and port for the configured vBond
    """

    vmanage_settings = Settings(ctx.auth, ctx.host)
    result = vmanage_settings.get_vmanage_vbond()
    if 'domainIp' in result:
        click.echo('{}:{}'.format(result['domainIp'], result['port']))
    else:
        click.echo("No vBond configured")
def org(ctx):
    """
    Get vManage org
    """

    vmanage_settings = Settings(ctx.auth, ctx.host, ctx.port)
    result = vmanage_settings.get_vmanage_org()
    if result:
        click.echo(f'{result}')
    else:
        click.echo("No org configured")
예제 #7
0
def run_module():
    # define available arguments/parameters a user can pass to the module
    argument_spec = vmanage_argument_spec()
    argument_spec.update(organization=dict(type='str'),
                         vbond=dict(type='str'),
                         vbond_port=dict(type='str', default='12346'),
                         root_cert=dict(type='str'),
                         ca_type=dict(type='str'))

    # seed the result dict in the object
    # we primarily care about changed and state
    # change is if this module effectively modified the target
    # state will include any data that you want your module to pass back
    # for consumption, for example, in a subsequent task
    result = dict(changed=False, )

    # the AnsibleModule object will be our abstraction working with Ansible
    # this includes instantiation, a couple of common attr would be the
    # args/params passed to the execution, as well as if the module
    # supports check mode
    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )
    vmanage = Vmanage(module)
    vmanage_settings = Settings(vmanage.auth, vmanage.host)
    vmanage_certificate = Certificate(vmanage.auth, vmanage.host)
    vmanage.result['what_changed'] = []

    if vmanage.params['organization']:
        current = vmanage_settings.get_vmanage_org()
        if vmanage.params['organization'] != current:
            vmanage.result['what_changed'].append('organization')
            if not module.check_mode:
                vmanage_settings.set_vmanage_org(
                    vmanage.params['organization'])

    if vmanage.params['vbond']:
        current = vmanage_settings.get_vmanage_vbond()
        if vmanage.params['vbond'] != current['domainIp'] or vmanage.params[
                'vbond_port'] != current['port']:
            vmanage.result['what_changed'].append('vbond')
            if not module.check_mode:
                vmanage_settings.set_vmanage_vbond(
                    vmanage.params['vbond'], vmanage.params['vbond_port'])

    if vmanage.params['ca_type']:
        current = vmanage_settings.get_vmanage_ca_type()
        if vmanage.params['ca_type'] != current:
            vmanage.result['what_changed'].append('ca_type')
            if not module.check_mode:
                vmanage_settings.set_vmanage_ca_type(vmanage.params['ca_type'])

    if vmanage.params['root_cert']:
        current = vmanage_certificate.get_vmanage_root_cert()
        if vmanage.params['root_cert'] not in current:
            vmanage.result['what_changed'].append('root_cert')
            if not module.check_mode:
                vmanage_settings.set_vmanage_root_cert(
                    vmanage.params['root_cert'])

    if vmanage.result['what_changed']:
        vmanage.result['changed'] = True

    vmanage.exit_json(**vmanage.result)
예제 #8
0
def root_cert(ctx, input_file):
    """
    Import root cert
    """
    vmanage_settings = Settings(ctx.auth, ctx.host, ctx.port)
    vmanage_settings.set_vmanage_root_cert(input_file)
예제 #9
0
 def __set_vmanage_setting(self):
     auth = Authentication(host=self.vm_mgmt_ip,
                           user=self.vm_user,
                           password=self.vm_pass).login()
     with open(f'{self.cert_path}/{self.rootca_name}', "r") as fn:
         vmanage_cert_root = fn.read()
     vm_setting = Settings(auth, self.vm_mgmt_ip)
     if vm_setting.get_vmanage_org() != self.org.strip():
         vm_setting.set_vmanage_org(self.org)
     if vm_setting.get_vmanage_ca_type() != "enterprise":
         vm_setting.set_vmanage_ca_type("enterprise")
     vm_setting.set_vmanage_root_cert(vmanage_cert_root)
     vm_setting.set_vmanage_vbond(self.vm_bond_vpn0_ip)
     self.__logger.info(vm_setting.get_vmanage_ca_type())
     self.__logger.info(vm_setting.get_vmanage_org())
     self.__logger.info(vm_setting.get_vmanage_vbond())
     self.__logger.info(vm_setting.get_vmanage_ca_type())